Problem description
A background service in Android stops running when the user exits the app using the BACK button. The same service works fine if the app is in foreground or in background (clicking the HOME button).
Steps to reproduce
- Create an app as explained in this GIST:
https://gist.github.com/e309f6a56ea6cb1fd394
- Run the app on Android: as soon as the app starts, a notification is shown every 10 seconds
After that, there are 3 cases:
1. Keep the app running: every 10 seconds a notification is shown (OK).
2. Put the app in background by clicking the HOME button: notifications keep showing (OK)
3. Click the BACK button (this closes the app): the background service is stopped and no more notifications are shown (BUG)
Expected behavior
Also in case #3, the notifications should keep running every 10 seconds.
Customer ticket
http://support.appcelerator.com/tickets/APP-829749
Testing Notes
* Create a new app and use the code in the Gist referred to in this item's description. That means including the notification.js and the* Put this in your test app's tiapp.xml:
* Run the app on device or simulator. * When the app starts, you'll notice right away a notification in the notification area. Another is added each 10 seconds. You don't need to do anything with these notifications, just notice that they are there and happening each 10 seconds. * Back out of the app. * In the fail case, no more notifications will come in the 10-sec intervals. When testing the fix, they *should* continue to come. * When testing the fix: go back into the app after you are satisfied that the notifications are still coming in every 10 seconds. * Click the "Stop service" button. * Back out of the app. * Check logcat. You should see:
That proves that the runtime does indeed shutdown (which is good for memory) when there are no more running services or activities that need it.
PR ready now: https://github.com/appcelerator/titanium_mobile/pull/2658
Verified fixed with: Titanium Studio, build: 2.1.1.201207271312 SDK version: 2.2.0.v20120813184911 Devices: LG VS910 4G (2.3.6) Samsung Galaxy Nexus (4.0.4)
Reopen to update label