Hi
The following code is for scheduling a service:
When the app is exiting, the CancelScheduledService does not seem to do the job, as the service start again.
Any idea's ?
Regards
John.
The following code is for scheduling a service:
B4X:
Sub schedulecallback(timeToAlarm As Long)
Dim p As Phone
' // zero check
If timeToAlarm = 0 Then
Return
End If
If p.SdkVersion >= 23 Then
Dim srvAt As JavaObject
srvAt.InitializeContext
srvAt.RunMethod("StartServiceAtExactWhileIdle", Array(timeToAlarm, True))
Else
'mod_functions.writelog("svc_watchdog(), call back using StartServiceAtExact()")
StartServiceAtExact(Me,timeToAlarm,True)
End If
End Sub
#If JAVA
//import android.app.Service;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
public void StartServiceAtExactWhileIdle(Long time, Boolean wakeUp){
AlarmManager alMan = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this.getApplicationContext(), this.getClass());
PendingIntent penInt = PendingIntent.getService(this.getApplicationContext(), 1, intent, 134217728);
alMan.setExactAndAllowWhileIdle(wakeUp?AlarmManager.RTC_WAKEUP:AlarmManager.RTC, time, penInt);
}
#End If
When the app is exiting, the CancelScheduledService does not seem to do the job, as the service start again.
Any idea's ?
Regards
John.