Runnable should start only one time

28 Views Asked by At

how can I prevent the runnable from being started a second time when the app is restarted? The runnable sends messages out at a certain interval.

I've been working with SharedPrefrences and it doesn't work because the runnable's termination isn't auditable.

1

There are 1 best solutions below

0
Mand On

I have a solution now. The runnable saves the current timemillis in sharedpreferences every second and the new instance of the app can check whether the timemillis are more than one second ago. this determines whether the runnable is still running or not.