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 did not work when the phone:
-was sleeping
-cleared all the apps using the
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!
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
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: