Android Question StartServiceAtExact not working

FreemanHK

Member
I am now developing an app which requires a service that starts at exact time.

After testing the app on a HUAWEI Mate 20 X (Android 10), I found that the service was not always working.

Code #1:
StartServiceAtExact(Scount,NextTimeInstance(00, 00), True)

Code #2:
Sub SetExactAndAllowWhileIdle (Time As Long, ServiceName As String)
   Dim p As Phone
   If p.SdkVersion < 23 Then
     StartServiceAtExact(ServiceName, Time, True)
   Else
     Dim in As Intent
     in.Initialize("", "")
     in.SetComponent(Application.PackageName & "/." &  ServiceName.ToLowerCase)
     Dim jin As JavaObject = in
     jin.RunMethod("setAction", Array(Null))
     Dim ctxt As JavaObject
     ctxt.InitializeContext
     Dim am As JavaObject = ctxt.RunMethod("getSystemService", Array("alarm"))
     Dim pi As JavaObject
     pi = pi.InitializeStatic("android.app.PendingIntent").RunMethod("getService", _
  Array(ctxt, 1, in, 134217728))
     am.RunMethod("setExactAndAllowWhileIdle", Array(0, Time, pi))
   End If
End Sub

Code #1 did not work when the phone:
-was sleeping
-cleared all the apps using the
android-recent-icon-100250724-orig.png
button
It sometimes worked when the app was open.
Code #2 did not work at all!

How can I start a service that ALWAYS WORKS at EXACT TIME?

Thanks!
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
I compiled my app using SDK V.23 and android.jar V.23
Sounds like a big mistake. You are probably using an outdated, deprecated, SDK.


Go over the installation instructions and carefully follow them and install it all new.

Per default B4A should use android.jar from api 28. Even targetsdk 28 should be set. But start with replacing your old SDK with a fresh one.

Do not use a SDK you are using with Android Studio oder any other Environment. Install a different SDK for B4X
 
Upvote 0
Top