In Activity I have some kind of timeout for user action. If user do nothing I need produce some other action for system. For this I am using Handler
protected void stopTimeout()
{
handler.removeMessages(0);
}
private void startTimeout()
{
stopTimeout();
handler.postDelayed(new Runnable()
{
@Override
public void run()
{
//SOME ACTIONS
}
}, 180 * 1000L);
}
Handler can be stopped for some user actions like buttons click
btnCancel.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View view)
{
// user actions
stopTimeout();
}
});
But at the moment I have to many variants of user actions. All this push to stopTimout from async threads and handler doesn't look as proper decision. Project I am already migrating to RXJava and
I can figure out how to done this part with RXJava.
removeMessagesAndCallbacks(null)for clearing the Handler.