I want to send an event to firebase if user spend a minimum of 20sec on my app. This looks simple enough as I only have to create a timer. Here is what I've done so far:
Subscription sessionEvent = Observable.timer(20, TimeUnit.SECONDS)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(aLong -> Log.v("tag", "hello"));
I am subscribing inside the onResume
of my activity while unsubscribing inside onPause
.
This is however a problem since if my activity started another activity, onPause
will also be called. That means that the timer will stop even though the user is still on my app.
What I'm looking for is when the user closed the app, that's when the timer will stop. I already tried using the onUserLeaveHint
, unfortunately, starting another activity will also call that method.