android监测本地服务
一、
private boolean isMyServiceRunning(){
ActivityManager manager= (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for(RunningServiceInfo service: manager.getRunningServices(Integer.MAX_VALUE))
{
if(MyService.class.getName().equals(service.service.getClassName()))
{
returntrue;
}
}
returnfalse;
}
二、启动服务必须用startserver()
Intent bindIntent = new Intent(this,ServiceTask.class);
startService(bindIntent);
bindService(bindIntent,mConnection,0);
public class ServiceTools {
private static String LOG_TAG = ServiceTools.class.getName();
public static boolean isServiceRunning(String serviceClassName)
{
final ActivityManager activityManager = (ActivityManager)Application.getContext().getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE);
for (RunningServiceInfo runningServiceInfo : services)
{
if (runningServiceInfo.service.getClassName().equals(serviceClassName))
{
return true;
}
}
&nb
补充:移动开发 , Android ,