是否可以在启动外部应用程序时停止服务?
对于活动,您可以使用getRunningAppProcesses()
并在列表中检查您想要的应用是否正在运行。但是服务呢?
答案 0 :(得分:0)
使用此:
public class TestService extends Service {
@Override
public void onCreate()
{
ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
List rs = am.getRunningServices(50);
for (int i=0; i<rs.size(); i++) {
ActivityManager.RunningServiceInfo rsi = (RunningServiceInfo) rs.get(i);
Log.i("Service", "Process " + rsi.process + " with component " + rsi.service.getClassName());
}
super.onDestroy();
Toast.makeText(getApplicationContext(),"1. onCreate()", Toast.LENGTH_SHORT).show();
}
}