The app and background service work together. But when the application is closed, does the background service restart?
What for? How to block this restart?
When the application is closed, the service should continue as if nothing had happened. How can i do this?
I use these codes in MainActivity:
tryConnect ();
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
private void tryConnect(){
if(!isMyServiceRunning(BackService.class)){
startService(new Intent(this,BackService.class));
}
}
Return help desk START_STICKY; (and I tried START_NOT_STICKY, START_REDELIVER_INTENT, not working)
I don't have onDestroy in the Android app.
source
share