我创建了一个运行活动和服务的Android应用程序。
我已经停止了活动的ondestroy()函数中的服务。
但即使应用程序已关闭&调用ondestroy(),该过程仍然可以在Settings - >中看到。应用程序 - >运行服务。
我应该如何完全关闭它?
我正用于启动服务的代码:
// initService is called from onCreate() in MainActivity
public void initService() {
try {
serviceConnection = new CallService();
Intent serviceIntent = new Intent();
serviceIntent.setClassName("com.example.working",
com.example.working.MyService.class.getName());
boolean ret = this.bindService(serviceIntent, serviceConnection,
Context.BIND_AUTO_CREATE);
Toast.makeText(MainActivity.this, "Service bound : " + ret,
Toast.LENGTH_SHORT).show(); // Return true or false
} catch (Exception e) {
Toast.makeText(this, "initService(): " + e.toString(), Toast.LENGTH_SHORT)
.show();
}
}
class CallService implements ServiceConnection {
@Override
public void onServiceConnected(ComponentName name, IBinder boundInterface) {
try {
Toast.makeText(MainActivity.this, "Service Connected", Toast.LENGTH_SHORT)
.show();
aidlObject = WorkingAidl.Stub.asInterface((IBinder) boundInterface);
} catch (Exception e) {
Toast.makeText(MainActivity.this, "onServiceConnected: " + e.toString(),
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onServiceDisconnected(ComponentName paramComponentName) {
aidlObject = null;
Toast.makeText(MainActivity.this, "Service Disconnected", Toast.LENGTH_SHORT)
.show();
}
}
由于