使用目标是要关闭指定的程序 彻底的,但是根据观察看来有一些应用再被关闭了之后可能会根据service再启动
所以需要这个类 -- ActivityManager
其中的api去获取正在开启的服务
This class gives information about,
and interacts with, activities, services, and the containing process.
A number of the methods in this class are for debugging
or informational purposes and they should not be used to affect any
runtime behavior of your app. These methods are called out as such
in the method level documentation.
代码如下:
private List<ActivityManager.RunningServiceInfo> getService(){
List<ActivityManager.RunningServiceInfo> list = new ArrayList<>();
ActivityManager manager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
list = manager.getRunningServices(40);
for(int i=0;i<list.size();i++){
Log.d("serviceName",list.get(i).service.getClassName());
}
return list;
}
虽然getRunningService已经被废弃然而还是可以使用的。
网友评论