So i have a background service running. Now, if the user quits the activity, the service will still be running, right? Now when user restarts the app, I want to access the background service and call some methods. How can I access the instance of the background service ?
Thanks Guys!
This worked for me out of the box!However do not use it if you have alternatives because public static members are not good unless they are final. You can create a static variable with public scope in the Service.
public static BackgroundService bs;
@Override
public void onCreate(){
bs=this;}
Then initialize the variable with 'this' which makes it a reference to the current running service. Use it as a reference in your activity anytime.
If the service continues to run after you quit your activity depends on how you start it. (Read about this in the documentation startService() / bindService()) If your Service is still running, then calls to startService()/bindService() will connect you to your 'old' service.
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