Widget Starting A Service Also Starts Main Activity
I have a widget that is supposed to start and stop a service (start it when it's not running, stop it when it is). This is working fine, however, each time the service is started,
Solution 1:
Your solution is not a good one, for example onPause() occurs when the user changes orientation (rotates the cell phone), so your app is going to just disappear when that happens.
I asked and found the solution: Why does starting an activity from a widget cause my main activity to start as well?
Solution 2:
I now 'solved' it by adding a finish();
to my main activity's onPause()
. Not a nice solution, but the main activity isn't heavy, so reloading it (rather than getting it back from memory) shouldn't do too much harm. Still weird and I would love to know what I'm doing wrong :)!
Solution 3:
Add finish()
to the activity after it starts the service.
Post a Comment for "Widget Starting A Service Also Starts Main Activity"