Service terminated

wl

Well-Known Member
Licensed User
Longtime User
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
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
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

wl

Well-Known Member
Licensed User
Longtime User
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

wl

Well-Known Member
Licensed User
Longtime User
I tried to put the service in the foreground, as follows

B4X:
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:

B4X:
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

wl

Well-Known Member
Licensed User
Longtime User
Think I found it myself:

Needed to set the SetInfo first and call the StartForeground in Service_Start

B4X:
Sub Service_Start (StartingIntent As Intent)
   notif.SetInfo ("Notification", "Foreground", Main)
   Service.StartForeground(1, notif)
End Sub
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
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
Top