Android Question Service always running

taylorw

Active Member
Licensed User
Erel this is my sample project.
And can i do like this?

B4X:
Sub Service_Destroy
   
    StartServiceAt("",DateTime.Now + 10*10, True)

End Sub
 

Attachments

  • Sample.zip
    388.2 KB · Views: 296
Upvote 0

taylorw

Active Member
Licensed User
Sorry, that is my mistake.
Now i change like this.
B4X:
Sub Service_Destroy
  
    StartServiceAt("",DateTime.Now + 10 * 1000, True)

End Sub

But when i lock screen it will be kill again.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I did several attempts.
I tried the code on different devices, android 4, 4.20, 5, 5.1 and 6

This anomaly occurs only on Huawei with Android 6.0

So I suppose either the version of Android or the Huawei firmware is the same as Honor

StartServiceAt is good solution
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I tried on an Asus ZenFone 2 with Android 6.01 and it works correctly. The operating system kills the app but the service stays sticky, so it works properly.
 
Upvote 0

Alpandino

Member
Licensed User
Sorry, why I'd call StartServiceAt instead of making my service a "sticky" service? Making a service "sticky" using
#StartCommandReturnValue: android.app.Service.START_STICKY

should restart my service if someone will kill it, right?
 
Upvote 0

Alpandino

Member
Licensed User
It is not instead of a sticky service. You can make the service both sticky and use StartServiceAt to ask the OS to start it from time to time.

Background processes are becoming more and more restricted in newer versions of Android.
But I have read that a service should restart if someone will kill it, right?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…