[TIMOB-3286] Android: Support service constants
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-02-17T15:06:10.000+0000 |
Affected Version/s | Release 1.7.0 |
Fix Version/s | Sprint 2012-04, Release 2.0.0 |
Components | Android |
Labels | n/a |
Reporter | MarkE |
Assignee | Bill Dawson |
Created | 2011-04-15T03:41:19.000+0000 |
Updated | 2017-03-24T20:51:40.000+0000 |
Description
Is it possible to add support for the constants for services for better control over the instances through Ti.Android.Service and the start event handler?
I'm finding my Android background service is getting cleared up when the device is running low on memory. I guess the alternative is support for foreground services.
Android Docs: http://developer.android.com/reference/android/app/Service.html#START_STICKY">
http://developer.android.com/reference/android/app/Service.html#STA...
QA Thread: http://developer.appcelerator.com/question/116757/creating-services-with-startsticky">
http://developer.appcelerator.com/question/116757/creating-services...
Attachments
File | Date | Size |
---|---|---|
timob3286.zip | 2012-02-15T13:17:59.000+0000 | 2320728 |
Really need to have support for Android Service StartForeground method.
Meant to include this link http://developer.android.com/reference/android/app/Service.html#startForeground(int, android.app.Notification)
Testing Notes
* Unzip the attached timob3286.zip and import it into Titanium Studio. * Run the app *on an Emulator* (because we're going to do some stuff inadb
that you're non-rooted phone probably won't allow.) * Go to Terminal (command prompt, whatevs) and enteradb logcat
. * You should see messages such as "hello from inside the service JS code" passing by. This is aTi.API.info
message from inside the test service's Javascript (testservice.js). * Now doadb shell ps
in Terminal. You'll see a list of processes running on the emulator. Find com.billdawson.timob3286 and note its PID. It's typically the number in the second column, like here it's 485:* Now do
adb shell "kill -2 PID"
in Terminal, but replace PID with the number you got in the previous step. E.g.,* Real quick do
adb logcat
again and look at the logcat output. Now you should see indications that the application was killed, plus an indication that the system will restart the Service that was running in the application. It will tell you how many milliseconds will elapse before it tries to restart the service. Example:* The example above shows that Android will restart the service in about 5 seconds. You should see something similar (warning: sometimes Android hikes this number up considerably, like up to 5 _minutes_). * Sit there and wait until the time has elapsed, keeping your eye on logcat output. * When the time elapses, the logcat output should show you that the service has been restarted. You should start seeing the "hello from inside the service JS code" messages fly by again. So the above steps, if successful, prove that
startMode: Ti.Android.START_REDELIVER_INTENT
functions correctly (you'll see that line in app.js). That constant means "if I get killed, then restart me, and when you restart me, send me again the Intent that originally started me." Now you need to test two more variants: a) Change app.js by removingstartMode: Ti.Android.START_REDELIVER_INTENT
and re-installing, re-running the app. Follow the steps above. The behavior should be the same (the milliseconds until restart may change -- Android seems to randomize that.) This proves thatSTART_REDELIVER_INTENT
is the default behavior, so if you don't specifystartMode
it will behave as though you did specifySTART_REDELIVER_INTENT
. b) Change app.js again, this time putstartMode: Ti.Android.START_NOT_STICKY
, then re-install and re-run the app. Follow the steps above. *However*, this time the service should *not* restart. (Even if Android says it's scheduling the restart of the service, when the time elapses it should not, in fact, be restarted.)START_NOT_STICKY
is your way of telling Android, "Hey, if you decide to kill me off to save memory, that's okay, and you don't even need to restart me later, I'm totally cool with that, muchacho."Pull request ready: https://github.com/appcelerator/titanium_mobile/pull/1433
i'm testing the REDELIVER_INTENT example with 3.2.0 and receive the following log:
the service won't restart. can you verify that it is still working there? Android 4.4.2, Nexus 4, Ti 3.2.0
Closing ticket as fixed.