Thursday, 19 September 2013

Cancel handler.postdelayed from another activity in which it was not created

Cancel handler.postdelayed from another activity in which it was not created

Mind the typos, just a mock up.
class myActivity1 extends Activity
{
oncreate()
{
Handler myHandler = new Handler();
myHandler.postDelayed(myRunnable,1000)
}
onPause()
{
}
}
The handler does its job, and after 1 second the myRunnable runs. Assuming
I call another postDelayed inside my myRunnable, that restarts the
postDelayed for repetition.
In myActivity1 I am not using the removeCallbacks() function, thus the
myHandler will be running even if I leave the activity.
However, my question is, HOW CAN I CANCEL the myHandler from inside
another activity that I moved to ? (Assume my app has 15 activites, and I
do not know inside which one I am.)

No comments:

Post a Comment