I'm using rxjava and rxandroid. In my presenter i have used
Observable.timer(10, TimeUnit.SECONDS);
And I would like to save time on screen orientation change. For example timer starts and after 3 seconds user is changing screen orientation, and timer starts again but from 0 for 10 seconds, but it needs to run for 7 remaining seconds.
Do you know any solution?
When you orientate your device, it recall
onCreate()
method of your activity and redraw your views. For this you can create a helper fragment and put your operations in that fragment. Put this linesetRetainInstance(true);
inonCreate()
method. Then, do your operations onAsyncTask
. If you wand display each second of timer in your screen, then callonProgressUpdate()
method of yourAsyncTask
class. Then, create an interface, withProgress
callback and put this callback inonProgressUpdate()
method. Then you can handle this operations via implementing that interface which you created in your fragment. I have simple repository in github which can help you. Enjoy. This article also can help you: Enjoy.