W wl Well-Known Member Licensed User Longtime User Apr 18, 2012 #1 Hello, I have a test application with just one activity with a button. Clicking on the button starts a service ("start at boot"). In the destroy event of the service I restart the service after 10 seconds. When I kill the application using a task kiler it seems both the activity and the service are stopped and the service is not restarted after 10 seconds. What am I missing ? Thanks !
Hello, I have a test application with just one activity with a button. Clicking on the button starts a service ("start at boot"). In the destroy event of the service I restart the service after 10 seconds. When I kill the application using a task kiler it seems both the activity and the service are stopped and the service is not restarted after 10 seconds. What am I missing ? Thanks !
kolbe Active Member Licensed User Longtime User Apr 19, 2012 #2 I asked a similar question. http://www.b4x.com/forum/basic4android-updates-questions/16996-question-about-process-globals-services.html#post97156 It seems that once the process (not the activity) is terminated, the service is terminated along with any service scheduling. In your case don't ExitApplication to keep the process and therefore the scheduled service alive. If I understand correctly Android will not immediately kill the process once you have exited the activity. Upvote 0
I asked a similar question. http://www.b4x.com/forum/basic4android-updates-questions/16996-question-about-process-globals-services.html#post97156 It seems that once the process (not the activity) is terminated, the service is terminated along with any service scheduling. In your case don't ExitApplication to keep the process and therefore the scheduled service alive. If I understand correctly Android will not immediately kill the process once you have exited the activity.
W wl Well-Known Member Licensed User Longtime User Apr 19, 2012 #3 ok thanks, I missed this ... But will Android decide one time or another to kill the process (and the service along with it) ? And if so: will I get into the Service Destroy event so I can restart it after 5 seconds ? Upvote 0
ok thanks, I missed this ... But will Android decide one time or another to kill the process (and the service along with it) ? And if so: will I get into the Service Destroy event so I can restart it after 5 seconds ?
Erel B4X founder Staff member Licensed User Longtime User Apr 19, 2012 #4 But will Android decide one time or another to kill the process (and the service along with it) ? Click to expand... Yes, unless you call Service.StartForeground. And if so: will I get into the Service Destroy event so I can restart it after 5 seconds ? Click to expand... It should work. Upvote 0
But will Android decide one time or another to kill the process (and the service along with it) ? Click to expand... Yes, unless you call Service.StartForeground. And if so: will I get into the Service Destroy event so I can restart it after 5 seconds ? Click to expand... It should work.
W wl Well-Known Member Licensed User Longtime User Apr 20, 2012 #5 Hi, It seems Android keeps killing the service with the open (but idle) TCP connection ? Running the service in foreground is lethal for the battery ... Wim Upvote 0
Hi, It seems Android keeps killing the service with the open (but idle) TCP connection ? Running the service in foreground is lethal for the battery ... Wim
Erel B4X founder Staff member Licensed User Longtime User Apr 20, 2012 #6 Running the service in the foreground doesn't have any special effect on the battery. It just prevents the service from being killed which is exactly what you are trying to achieve. Your solution will have the exact same impact on the battery. Upvote 0
Running the service in the foreground doesn't have any special effect on the battery. It just prevents the service from being killed which is exactly what you are trying to achieve. Your solution will have the exact same impact on the battery.
W wl Well-Known Member Licensed User Longtime User Apr 20, 2012 #7 I tried to put the service in the foreground, as follows Code: Sub Service_Create notif.Initialize notif.Icon ="icon" notif.Vibrate = True notif.Light = True Service.StartForeground(1, notif) End Sub But the application crashes and this is in my log files: Code: android.app.RemoteServiceException: Bad notification for startForeground: java.lang.IllegalArgumentException: contentView required: pkg=net.wapps.mpush id=1 notification=Notification(vibrate=default,sound=default,defaults=0xffffffff,flags=0x40) Anyone an idea ? Thanks ! Upvote 0
I tried to put the service in the foreground, as follows Code: Sub Service_Create notif.Initialize notif.Icon ="icon" notif.Vibrate = True notif.Light = True Service.StartForeground(1, notif) End Sub But the application crashes and this is in my log files: Code: android.app.RemoteServiceException: Bad notification for startForeground: java.lang.IllegalArgumentException: contentView required: pkg=net.wapps.mpush id=1 notification=Notification(vibrate=default,sound=default,defaults=0xffffffff,flags=0x40) Anyone an idea ? Thanks !
W wl Well-Known Member Licensed User Longtime User Apr 20, 2012 #8 Think I found it myself: Needed to set the SetInfo first and call the StartForeground in Service_Start Code: Sub Service_Start (StartingIntent As Intent) notif.SetInfo ("Notification", "Foreground", Main) Service.StartForeground(1, notif) End Sub Upvote 0
Think I found it myself: Needed to set the SetInfo first and call the StartForeground in Service_Start Code: Sub Service_Start (StartingIntent As Intent) notif.SetInfo ("Notification", "Foreground", Main) Service.StartForeground(1, notif) End Sub
W wl Well-Known Member Licensed User Longtime User Apr 20, 2012 #9 What I notice is that when I lock the phone by pressing the on/off button (not shutting it down!) after a while the service stops responding. When I press the on/off button again the service kicks in again. How can I make sure the service continues when I press the on/off button ? Thanks ! Upvote 0
What I notice is that when I lock the phone by pressing the on/off button (not shutting it down!) after a while the service stops responding. When I press the on/off button again the service kicks in again. How can I make sure the service continues when I press the on/off button ? Thanks !
Erel B4X founder Staff member Licensed User Longtime User Apr 22, 2012 #10 See PhoneWakeState from the Phone library. You should use PartialLock. Upvote 0