I have a scenario where an activity starts a service by invoking the startService method: both the Activity and the Service are in the same package. Then the service, according to its configuration parameters, could launch an activity (Let's call it ExternalActivity) contained in a different package: this activity bind the service through bindService; once this activity has finished its tasks, it calls the unbindService method as follows...
// method of ExternalActivity
@Override
public void onDestroy() {
super.onDestroy();
unbindService(...);
}
As a consequence, the service is also destroyed. Is there the possibility of avoiding the destruction of the service?
As a consequence, the service is also destroyed.
As yorkw explained, a service is destroyed only when both of the following are true:
All calls to bindService() have been matched by corresponding calls to unbindService().
If somebody called startService(), somebody also called stopService() or the service called stopSelf().
Is there the possibility of avoiding the destruction of the service?
Find a better time to call stopService() or stopSelf(), whichever of those you are using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With