I have an Android Wear (WearOS) app that after running for a very long period of time ( say 1 hour plus ) sometimes loses its state.
By losing its state I mean after a long time running the app resumes in "State A" from its notification.
- State A: Stopped - idle.
- State B: Running - collecting GPS data.
However, if the app runs for let's say 20 mins it resumes rightly in "State B" from its notification.
My Service Class:
public int onStartCommand(Intent intent, int flags, int startId) {
Notification notification = this.createNotification();
super.startForeground(PID, notification);
return START_STICKY;
}
private Notification createNotification(){
Log.i("MyService", "createNotification");
Intent mainIntent = new Intent(this, MyActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0, mainIntent,0);
// shortened for breviety ... creates notification ...
return notification;
}
My Activity Class:
private void startWatching() {
if(this.intentService != null){
this.stopGpsAndCloseDb();
}
this.intentService = new Intent(this, MyService.class);
this.intentService.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
super.startService(intentService);
}
Could someone shed some light into this problem, what am I missing? Thanks!