My application has a few activities, and a background service. My question is, if I have the context variable in the service, how can I tell which activity is currently open? I need to do this to direct the next action my service takes. For example,
if (context is activity_1) {
//take this action
} else if (context is activity_2) {
//do this instead…
}
That’s the basic gist of what I’m trying to do.
Help much appreciated.
You could set a SharedPreferences entry in each
onResume()method of your activities and read that value from the service. To keep it clean you could write an Activity that does that and then extend all your activities from it:in your service than just call: