Sub Service_TaskRemoved
SetExactAndAllowWhileIdle(DateTime.Now+DateTime.TicksPerSecond * 10,"sv1")
StopService(sv2)
Log("App is killed")
End Sub
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