A. android 获取系统运行的服务
参数为最大返回数目。
这个值一般填大一点就没问题了,直接给个100。我们没办法直接得到那个值。
不用担心万一不够一百怎么办
amanager.getRunningServices(100)他返回的是个LIST集合,你只有20个服务list.size()显示出来也就是20.对你没任何影响。
当然万一大于100肯定是显示不全的。这个无法去避免,我们只能尽可能把这个值稍微填大一点。
但是手机不可能附带大于100的服务。现在的手机肯定带不了。有100个服务估计直接死机。
B. 什么是android的四大组件
Android四大组件有Activity,Service服务,Content Provider内容提供,BroadcastReceiver广播接收器。
Android应用程序由一些零散的有联系的组件组成,通过一个工程manifest绑定在一起。在manifest中,描述了每一个组件以及组件的作用,其中有6个组件,它们是Android应用程序的基石
(2)android服务列表扩展阅读
Activities(活动)
应用程序的显示层。每一个画面对应于你的应用程序,将会是Activity类的扩展。Activity使用Views去构建UI来显示信息和响应用户的行为。就桌面开发而言,一个Activity相当于一张Form。
Services(服务)
Android应用程序中不可见的“工人”。 Service组件运行时不可见,但它负责更新的数据源和可见的Activity,以及触发通知。它们常用来执行一些需要持续运行的处理,当你的 Activity已经不处于激活状态或不可见。
Content(内容)
提供共享的数据存储。Content Provider(内容提供器)用来管理和共享应用程序的数据库。在应用程序间,Content Provider是共享数据的首选方式。
Broadcast Receivers(广播接收器)
Intent广播的“消费者”。通过创建和注册一个Broadcast Receiver,应用程序可以监听符合特定条件的广播的Intent。Broadcast Receiver 会自动的启动你的Android应用程序去响应新来的Intent。Broadcast Receiver是事件驱动程序的理想手段。
参考资料来源:网络-Android组件
C. 怎么获取android系统服务,如Uri,intent参数等,或者说去哪里查看
android系统服务,如Uri,intent参数
可以在Intent中指定程序要执行的动作(比如:view,edit,dial),以及程序执行到该动作时所需要的资料。都指定好后,只要调用startActivity(),Android系统会自动寻找最符合你指定要求的应用程序,并执行该程序。
★intent大全:
1.从google搜索内容
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,"searchString")
startActivity(intent);
2.浏览网页
Uri uri =Uri.parse("htt。。。。。。。。om");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
3.显示地图
Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent it = newIntent(Intent.Action_VIEW,uri);
startActivity(it);
4.路径规划
Uri uri =Uri.parse("http。。。。。。。。。。/maps?
f=dsaddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
Intent it = newIntent(Intent.ACTION_VIEW,URI);
startActivity(it);
5.拨打电话
Uri uri =Uri.parse("tel:xxxxxx");
Intent it = new Intent(Intent.ACTION_DIAL,uri);
startActivity(it);
6.调用发短信的程序
Intent it = newIntent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "TheSMS text");
it.setType("vnd.android-dir/mms-sms");
startActivity(it);
7.发送短信
Uri uri =Uri.parse("smsto:0800000123");
Intent it = newIntent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "TheSMS text");
startActivity(it);
String body="this is sms demo";
Intent mmsintent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("smsto",
number, null));
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true);
startActivity(mmsintent);
8.发送彩信
Uri uri =Uri.parse("content://media/external/images/media/23");
Intent it = newIntent(Intent.ACTION_SEND);
it.putExtra("sms_body","some text");
it.putExtra(Intent.EXTRA_STREAM, uri);
it.setType("image/png");
startActivity(it);
StringBuilder sb = new StringBuilder();
sb.append("file://");
sb.append(fd.getAbsoluteFile());
Intent intent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto",
number, null));
// Below extra datas are all optional.
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT,subject);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI,sb.toString());
intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,composeMode);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,exitOnSent);
startActivity(intent);
9.发送Email
Uri uri =Uri.parse("mailto:[email protected]");
Intent it = newIntent(Intent.ACTION_SENDTO, uri);
startActivity(it);
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL,"[email protected]");
it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");
it.setType("text/plain");
startActivity(Intent.createChooser(it,"Choose Email Client"));
Intent it=new Intent(Intent.ACTION_SEND);
String[] tos={"[email protected]"};
String[]ccs={"[email protected]"};
it.putExtra(Intent.EXTRA_EMAIL, tos);
it.putExtra(Intent.EXTRA_CC, ccs);
it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");
it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");
it.setType("message/rfc822");
startActivity(Intent.createChooser(it,"Choose Email Client"));
Intent it = newIntent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");
it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3");
sendIntent.setType("audio/mp3");
startActivity(Intent.createChooser(it,"Choose Email Client"));
10.播放多媒体
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri =Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri,"audio/mp3");
startActivity(it);
Uri uri
=Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
11.uninstall apk
Uri uri =Uri.fromParts("package", strPackageName, null);
Intent it = newIntent(Intent.ACTION_DELETE, uri);
startActivity(it);
12.install apk
Uri installUri = Uri.fromParts("package","xxx", null);
returnIt = newIntent(Intent.ACTION_PACKAGE_ADDED, installUri);
打开照相机
<1>Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
this.sendBroadcast(i);
<2>long dateTaken = System.currentTimeMillis();
String name = createName(dateTaken) + ".jpg";
fileName = folder + name;
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, fileName);
values.put("_data", fileName);
values.put(Images.Media.PICASA_ID, fileName);
values.put(Images.Media.DISPLAY_NAME, fileName);
values.put(Images.Media.DESCRIPTION, fileName);
values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);
Uri photoUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);
Intent inttPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(inttPhoto, 10);
14.从gallery选取图片
Intent i = new Intent();
i.setType("image/*");
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(i, 11);
打开录音机
Intent mi = new Intent(Media.RECORD_SOUND_ACTION);
startActivity(mi);
16.显示应用详细列表
Uri uri =Uri.parse("market://details?id=app_id");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
//where app_id is the application ID, findthe ID
//by clicking on your application on Markethome
//page, and notice the ID from the addressbar
刚才找app id未果,结果发现用package name也可以
Uri uri =Uri.parse("market://details?id=");
这个简单多了
17寻找应用
Uri uri =Uri.parse("market://search?q=pname:pkg_name");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
//where pkg_name is the full package pathfor an application
18打开联系人列表
<1>
Intent i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
i.setType("vnd.android.cursor.item/phone");
startActivityForResult(i, REQUEST_TEXT);
<2>
Uri uri = Uri.parse("content://contacts/people");
Intent it = new Intent(Intent.ACTION_PICK, uri);
startActivityForResult(it, REQUEST_TEXT);
19 打开另一程序
Intent i = new Intent();
ComponentName cn = newComponentName("com.yellowbook.android2",
"com.yellowbook.android2.AndroidSearch");
i.setComponent(cn);
i.setAction("android.intent.action.MAIN");
startActivityForResult(i, RESULT_OK);
20.调用系统编辑添加联系人(高版本SDK有效):
Intent it = newIntent(Intent.ACTION_INSERT_OR_EDIT);
it.setType("vnd.android.cursor.item/contact");
//it.setType(Contacts.CONTENT_ITEM_TYPE);
it.putExtra("name","myName");
it.putExtra(android.provider.Contacts.Intents.Insert.COMPANY,
"organization");
it.putExtra(android.provider.Contacts.Intents.Insert.EMAIL,"email");
it.putExtra(android.provider.Contacts.Intents.Insert.PHONE,"homePhone");
it.putExtra(android.provider.Contacts.Intents.Insert.SECONDARY_PHONE,
"mobilePhone");
it.putExtra( android.provider.Contacts.Intents.Insert.TERTIARY_PHONE,
"workPhone");
it.putExtra(android.provider.Contacts.Intents.Insert.JOB_TITLE,"title");
startActivity(it);
21.调用系统编辑添加联系人(全有效):
Intent intent = newIntent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(People.CONTENT_ITEM_TYPE);
intent.putExtra(Contacts.Intents.Insert.NAME, "My Name");
intent.putExtra(Contacts.Intents.Insert.PHONE, "+1234567890");
intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE,Contacts.PhonesColumns.TYPE_MOBILE);
intent.putExtra(Contacts.Intents.Insert.EMAIL, "[email protected]");
intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE,
Contacts.ContactMethodsColumns.TYPE_WORK);
startActivity(intent);
★intent action大全:
android.intent.action.ALL_APPS
android.intent.action.ANSWER
android.intent.action.ATTACH_DATA
android.intent.action.BUG_REPORT
android.intent.action.CALL
android.intent.action.CALL_BUTTON
android.intent.action.CHOOSER
android.intent.action.CREATE_LIVE_FOLDER
android.intent.action.CREATE_SHORTCUT
android.intent.action.DELETE
android.intent.action.DIAL
android.intent.action.EDIT
android.intent.action.GET_CONTENT
android.intent.action.INSERT
android.intent.action.INSERT_OR_EDIT
android.intent.action.MAIN
android.intent.action.MEDIA_SEARCH
android.intent.action.PICK
android.intent.action.PICK_ACTIVITY
android.intent.action.RINGTONE_PICKER
android.intent.action.RUN
android.intent.action.SEARCH
android.intent.action.SEARCH_LONG_PRESS
android.intent.action.SEND
android.intent.action.SENDTO
android.intent.action.SET_WALLPAPER
android.intent.action.SYNC
android.intent.action.SYSTEM_TUTORIAL
android.intent.action.VIEW
android.intent.action.VOICE_COMMAND
android.intent.action.WEB_SEARCH
android.net.wifi.PICK_WIFI_NETWORK
android.settings.AIRPLANE_MODE_SETTINGS
android.settings.APN_SETTINGS
android.settings.APPLICATION_DEVELOPMENT_SETTINGS
android.settings.APPLICATION_SETTINGS
android.settings.BLUETOOTH_SETTINGS
android.settings.DATA_ROAMING_SETTINGS
android.settings.DATE_SETTINGS
android.settings.DISPLAY_SETTINGS
android.settings.INPUT_METHOD_SETTINGS
android.settings.INTERNAL_STORAGE_SETTINGS
android.settings.LOCALE_SETTINGS
android.settings.LOCATION_SOURCE_SETTINGS
android.settings.MANAGE_APPLICATIONS_SETTINGS
android.settings.MEMORY_CARD_SETTINGS
android.settings.NETWORK_OPERATOR_SETTINGS
android.settings.QUICK_LAUNCH_SETTINGS
android.settings.SECURITY_SETTINGS
android.settings.SETTINGS
android.settings.SOUND_SETTINGS
android.settings.SYNC_SETTINGS
android.settings.USER_DICTIONARY_SETTINGS
android.settings.WIFI_IP_SETTINGS
android.settings.WIFI_SETTINGS
android.settings.WIRELESS_SETTINGS
D. Android中AM、PM、mpsys命令使用总结
am指令是 activity manager的缩写,可以启动Service、Broadcast,杀进程,监控等功能,这些功能都非常便捷调试程序。
可以通过adb shell 进入Android 的Linux命令界面,输入am -help查看详细命令,先介绍几个简单用法,
命令格式如下
命令列表:
原理分析:am命令实的实现方式在Am.java,最终几乎都是调用ActivityManagerService相应的方法来完成的,am monitor除外。比如前面概述中介绍的命令am start -a android.intent.action.VIEW -d https://amberweather.com , 启动Acitivty最终调用的是ActivityManagerService类的startActivityAsUser()方法来完成的。再比如am kill-all命令,最终的实现工作是由ActivityManagerService的killBackgroundProcesses()方法完成的。
下面说一下[options]和 <INTENT>参数的意义以及如何正确取值。
主要是启动Activity命令am start [options] <INTENT>使用options参数,接下来列举Activity命令的[options]参数:
启动Activity的实现原理: 存在-W参数则调用startActivityAndWait()方法来运行,否则startActivityAsUser()。
命令
例如: 向pid=12345的进程,发出level=RUNNING_LOW的收紧内存命令
level取值范围为: HIDDEN、RUNNING_MODERATE、BACKGROUND、RUNNING_LOW、MODERATE、RUNNING_CRITICAL、COMPLETE
am的子命令,startservice, stopservice, broadcast, kill, profile start, profile stop, mpheap的可选参数都允许设置--user <USER_ID>。目前市面上的绝大多数手机还是单用户模式,因此可以忽略该参数,默认为当前用户。
例如:启动id=10001的用户的指定service。
Intent的参数和flags较多,为了方便,这里分为3种类型参数,常用参数,Extra参数,Flags参数
实例
(1). 基本类型
参数es是Extra String首字母简称,实例:
(2). 数组类型
参数eia,是Extra int array首字母简称,多个value值之间以逗号隔开,实例:
(3). ArrayList类型
参数efal,是Extra float Array List首字母简称,多个value值之间以逗号隔开,实例:
pm工具为包管理(package manager)的简称,可以使用pm工具来执行应用的安装和查询应用宝的信息、系统权限、控制应用,pm工具是Android开发与测试过程中必不可少的工具,shell命令格式如下:
原理分析:pm命令实的实现方式在Pm.java,最后大多数都是调用PackageManagerService相应的方法来完成的。disbale之后,在桌面和应用程序列表里边都看到不该app。
查看所有的package,
[options]参数:
disabled + enabled = 总应用个数; 系统 + 第三方 = 总应用个数。
查看第3方应用:
查看已经被禁用的包名
<FILTER>参数
当FILTER为不为空时,则只会输出包名带有FILTER字段的应用;当FILTER为空时,则默认显示所有满足条件的应用。
例如,查看包名带有weather字段的包名
[options]参数:
<PATH>参数: 指的是需要安装的apk所在的路径
mpsys是Android自带的强大debug工具,从名字就可以看出,主要是用于mp 当前android system的一些信息,是一项分析手机问题,运行状态,使用情况等十分有效的手段。
实现原理
mpsys的源码结构其实很简单,只有一个mpsys.cpp
/frameworks/native/cmds/mpsys/mpsys.cpp
先通过defaultServiceManager()函数获得ServiceManager对象,然后根据mpsys传进来的参数通过函数checkService来找到具体的service, 并执行该service的mp方法,达到mp service的目的。
不同的Android系统版本支持的命令有所不同,可通过下面命令查看当前手机所支持的mp服务,先进入adb shell,再执行如下命令:mpsys -l。 这些服务名可能并看不出其调用的哪个服务,可以通过下面指令:service list。
服务列表有很多,这里简单介绍几种
通过下面命令可打印具体某一项服务:mpsys <service>,其中service便是前面表格中的服务名
接下来主要说下mpsys activity 用法
命令
options可选值
mpsys activity等价于依次输出下面7条指令:
cmd可选值
命令
返回结果
上面的输出结果可以分为以下四个部分
也可以只输出某个pid或package的进程信息:
下面以AmberLocker作为实例进行分析
场景1:查询某个App所有的Service状态
解读:Service类名为com.amber.lockscreen.LockerHeartService,包名为mobi.infolife.ezweather.locker.locker_2,baseDir(apk路径)为/data/app/mobi.infolife.ezweather.locker.locker_2-2/base.apk,dataDir((apk数据路径)
运行在进程pid=1115,进程名为进程名为mobi.infolife.ezweather.locker.locker_2,,uid=10060,还有创建时间等信息
场景2:查询某个App所有的广播状态
场景3:查询某个App所有的Activity状态
场景4:查询某个App的进程状态
格式:ProcessRecord{Hashcode pid:进程名/uid},进程pid=941,进程名为mobi.infolife.ezweather.locker.locker_2:live,uid=10060.
该进程中还有Services,Connections, Providers, Receivers,
场景5:查询栈顶Activity
mpsys 的命令还有很多,这里就不一一列举了。
E. android如何获取服务器端文件列表及相关信息
要弄的话你先要搞清几个问题,
1、你与服务端的通信协议。如果一般服务端已经开发好了,那么会有一套通信协议,通常与手机的交互都采用JSON格式发送,减少流量。你可以网络下JSON的相关知识。很简单的一种格式。如果不是JSON的话一般会是XML,不过很少见。
2、数据量。Android market应用列表见过吧?很多情况下回做成懒加载,而不是刷新所有数据。这样的话你就要根据数据量考虑你的代码实现了,合理的使用SoftReference,优化ListView,用sqllite数据库缓存数据等等,具体机制你需要自己设计一下了,如果你是个PM的话。如果不是PM推荐你找个有经验的人设计下,否则很容易出现OOM异常
对于数据的处理方面,就像第一条说的,无论是JSON还是XML格式,android都有工具类,用法我就不贴了,自己搜一下,很多的
F. 列出Android设备中所有启动的服务,及判断某个服务是否开启
今天给大家的小例子是列出Android设备中所有启动的服务,及判断某个服务是否开启,具体步骤如下了:
第一步:新建一个Android工程,命名为RunningService。
第二步:修改RunningService.java代码如下:
package com.tutor.runningservice;
import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
import android.os.Bundle;
import android.widget.TextView;
public class RunningService extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
TextView mTextView = new TextView(this);
ActivityManager mActivityManager =
(ActivityManager)getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> mServiceList = mActivityManager.getRunningServices(30);
//我要判断的服务名字,我在launcher2里加了一个音乐服务
final String musicClassName = "com.android.launcher2.MusicService";
boolean b = MusicServiceIsStart(mServiceList, musicClassName);
mTextView.setText("你要判断的服务状态为: " +b+"/n" + getServiceClassName(mServiceList));
setContentView(mTextView);
}
//通过Service的类名来判断是否启动某个服务
private boolean MusicServiceIsStart(List<ActivityManager.RunningServiceInfo> mServiceList,String className){
for(int i = 0; i < mServiceList.size(); i ++){
if(className.equals(mServiceList.get(i).service.getClassName())){
return true;
}
}
return false;
}
//获取所有启动的服务的类名
private String getServiceClassName(List<ActivityManager.RunningServiceInfo> mServiceList){
String res = "";
for(int i = 0; i < mServiceList.size(); i ++){
res+=mServiceList.get(i).service.getClassName()+ " /n";
}
return res;
}
}
第三步:运行上述工程,查看效果!
G. 怎么查看Android设备中的启动服务
有两种方法,一种是设置里,有个位置和安全的选项,里面设置允许使用位置服务;第二种(安卓4.0以上)在下拉栏里点击“位置服务”案件,绿色就表示打开了。以上两种方法使用时都会在上面有一个位置服务标识中间在闪烁。
H. android中怎样获取手机已开启的应用列表
打开设置—应用程序—管理应用程序—正在运行的服务即可查看,并可以停止运行
用软件也行,安卓优化大师、360手机助手和腾讯手机管家都行,并可以禁止应用后台自启动
另外提醒你,短按两次home键是查看最近启动的应用程序,不能管理,也不是后台运行,只能快速打开
I. Android中服务service
本文原文连接 https://blog.csdn.net/wen20102321/article/details/53155736
Service是Android中的四大组件之一,它的级别和Activity差不多。只不过Service没有页面显示,只能后台运行,可以和其他组件进行交互。
Service的后台运行并不是子线程,是在主线程中进行的,只是它没有界面显示。如果Service进行了耗时操作同样需要开启子线程,否则会跟Activity一样出现ANR问题(application not response–程序没有响应)。
补充说明:
主线程的内容包括UI和后台,只要程序中的UI或者后台其中一个在跑,程序都算是在运行状态。
1,创建一个自己的TestService继承Service
2,必须实现重写其中的onBind方法,可以在里边做各种操作,也可以接收传递过来的Intent的数据。
(在Android Studio中可以直接新建一个Service)
服务的注册是四大组件中最简单的一个,一般只要设置name属性就可以了。
1,startService()启动
(1)启动服务startService:onCerate(),onStart()
(2)停止服务stopService:onDestroy()
此方法启动服务,服务如果未被创建,系统会先调用onCreate()方法,接着调用onStrat()方法。如果调用startService前服务已经被启动,多次调用启动方法,不会多次调用onCreate,但会导致多次调用onStrat。
2,bindService()启动
(1)绑定bindService:onCreate(),onBind()
(2)解除绑定unbindService:onUnbind()
(3)正常停止程序服务的方法是先接触绑定unbindService,在停止服务stopService
绑定后调用stopService方法,这时候是不能停止服务的,如果这时再调用解绑unbindService,程序会先解绑,后停止服务。
用此方法启动服务,在服务未被创建时,会先调用onCreate(),接着调用onBind()方法,这时候调用者和服务绑定在一起,调用者退出,系统会先调用服务的onUnbind(),然后onDestroy()。如果调用bindService之前服务已经被绑定,多次调用bindService并不会导致onCreate()和onBind()方法被多次调用。如果调用者想与正在绑定的服务解除绑定,可以调用unbindService()。
(1),onCerate()服务第一次被创建
(2),onStartComand()服务开始工作
(3),onBind()服务已经绑定
(4),onUnBind()服务解绑
(5),onDestroy()服务已经停止
普通的Service进行耗时操作要创建一个线程去完成,因为service是在主线程运行的,并且这个子线程完成工作要手动停止 。IntentService是继承了Service并处理起步请求的一个类,在IntentService内有一个工作线程,来处理耗时操作,启动IntentService的方式和启动传统的Service是一样,当任务执行完成后,IntentService会自动停止,而不需要我们去控制。
可以启动多次IntentService,每一个耗时操作会以工作队列的方式在IntentService的onHandleIntent回调方法中执行,并且每次只会执行一个工作线程,执行完第一个再执行第二个,以此类推,而且,所有请求都在一个单线程中,不会阻塞主线程,同一时间只处理一个请求。
IntentService优点
1,省去了在Service中开线程的麻烦
2,当操作完成时,不用手动停止Service。IntentService是Service,但是比Service更智能。
J. Android中Service服务有哪些
Service分为本地服务(LoaclService)和远程服务(RemoteService)。
本地服务:用于应用程序内部,这也与客户端(可以理解也activity)进行通信就很方便。
远程服务:用于android系统内部的应用程序之间。