Observable.timer saving state

158 Views Asked by At

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?

1

There are 1 best solutions below

3
On

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 line setRetainInstance(true); in onCreate() method. Then, do your operations onAsyncTask. If you wand display each second of timer in your screen, then call onProgressUpdate() method of your AsyncTask class. Then, create an interface, withProgress callback and put this callback in onProgressUpdate() 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.