蓝蓝的天 2019-06-27
List<ActivityManager.RunningServiceInfo> runningServiceInfoList = manager.getRunningServices(200); for (ActivityManager.RunningServiceInfo info : runningServiceInfoList) { //全路径类名 if ((getPackageName()+".ThreadService").equals( info.service.getClassName())){ //implement your code } }
每隔一分钟,系统会发送一次该广播,监听该广播,并通过第(3)步的代码来不间断的判断某个服务是否还存活。注意该广播无须在AndroidManifest.xml中注册
public class BootReceiver extends BroadcastReceiver{ @override public void onReceive(Context context, Intent intent) { if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) { //implement your code } }
<receiver android:name=".BootCompleteReceiver" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiver>