[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 inadbthat 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.infomessage from inside the test service's Javascript (testservice.js). * Now doadb shell psin 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 doadb shell "kill -2 PID"in Terminal, but replace PID with the number you got in the previous step. E.g.,* Real quick doadb logcatagain 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 thatstartMode: Ti.Android.START_REDELIVER_INTENTfunctions 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_INTENTand 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_INTENTis the default behavior, so if you don't specifystartModeit 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_STICKYis 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.001-20 22:43:13.368: I/TiAPI(17954): hello from _inside_ the service JS code 01-20 22:43:18.353: I/TiAPI(17954): hello from _inside_ the service JS code 01-20 22:43:19.404: D/AndroidRuntime(17990): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<< 01-20 22:43:19.404: D/AndroidRuntime(17990): CheckJNI is OFF 01-20 22:43:19.434: D/dalvikvm(17990): Trying to load lib libjavacore.so 0x0 01-20 22:43:19.444: D/dalvikvm(17990): Added shared lib libjavacore.so 0x0 01-20 22:43:19.454: D/dalvikvm(17990): Trying to load lib libnativehelper.so 0x0 01-20 22:43:19.454: D/dalvikvm(17990): Added shared lib libnativehelper.so 0x0 01-20 22:43:19.454: D/dalvikvm(17990): No JNI_OnLoad found in libnativehelper.so 0x0, skipping init 01-20 22:43:19.504: D/dalvikvm(17990): Note: class Landroid/app/ActivityManagerNative; has 179 unimplemented (abstract) methods 01-20 22:43:19.725: D/AndroidRuntime(17990): Calling main entry com.android.commands.am.Am 01-20 22:43:19.725: I/ActivityManager(610): Force stopping com.billdawson.timob3286 appid=10219 user=0: from pid 17990 01-20 22:43:19.725: I/ActivityManager(610): Killing 17954:com.billdawson.timob3286/u0a219 (adj 0): stop com.billdawson.timob3286 01-20 22:43:19.725: W/ActivityManager(610): Force removing ActivityRecord{41f16980 u0 com.billdawson.timob3286/org.appcelerator.titanium.TiActivity t1307}: app died, no saved state 01-20 22:43:19.735: I/ActivityManager(610): Force finishing activity ActivityRecord{41f0f1e0 u0 com.billdawson.timob3286/.Timob3286Activity t1307} 01-20 22:43:19.745: I/ActivityManager(610): Force stopping service ServiceRecord{437b1060 u0 com.billdawson.timob3286/.TestserviceService} 01-20 22:43:19.765: D/AndroidRuntime(17990): Shutting down VM 01-20 22:43:19.765: W/InputDispatcher(610): channel '426cf850 com.billdawson.timob3286/org.appcelerator.titanium.TiActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9 01-20 22:43:19.765: I/WindowState(610): WIN DEATH: Window{426c8370 u0 com.billdawson.timob3286/com.billdawson.timob3286.Timob3286Activity} 01-20 22:43:19.775: E/InputDispatcher(610): channel '426cf850 com.billdawson.timob3286/org.appcelerator.titanium.TiActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 01-20 22:43:19.775: D/jdwp(17990): Got wake-up signal, bailing out of select 01-20 22:43:19.775: D/dalvikvm(17990): Debugger has detached; object registry had 1 entries 01-20 22:43:19.785: W/InputDispatcher(610): Attempted to unregister already unregistered input channel '426cf850 com.billdawson.timob3286/org.appcelerator.titanium.TiActivity (server)' 01-20 22:43:19.785: I/WindowState(610): WIN DEATH: Window{426cf850 u0 com.billdawson.timob3286/org.appcelerator.titanium.TiActivity} 01-20 22:43:19.885: W/Binder(852): Caught a RuntimeException from the binder stub implementation. 01-20 22:43:19.885: W/Binder(852): java.lang.NullPointerException 01-20 22:43:19.885: W/Binder(852): at android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280) 01-20 22:43:19.885: W/Binder(852): at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129) 01-20 22:43:19.885: W/Binder(852): at android.os.Binder.execTransact(Binder.java:404) 01-20 22:43:19.885: W/Binder(852): at dalvik.system.NativeStart.run(Native Method) 01-20 22:43:19.885: W/InputMethodManagerService(610): Got RemoteException sending setActive(false) notification to pid 17954 uid 10219 01-20 22:43:20.005: V/RenderScript(17769): Application requested CPU execution 01-20 22:43:20.015: V/RenderScript(17769): 0x7683d6a8 Launching thread(s), CPUs 4Closing ticket as fixed.