Hamid Hamid - 5 months ago 32
Android Question

Android, pausing and resuming handler callbacks

I have a handler that I am using as follows:

handler.postDelayed(Play, 1000);


when my application onPause() is called before this is done, I need to pause it and tell it not to perform the "postDelayed" until I resume.

is this possible, or is there an alternative way?

My problem is that when onPause() is called I pause the audio (SoundManager), but if this handler.postDelayed is called after that, the audio will not be paused and will continue to play with my application in the background.

@Override
public void onPause()
{
Soundmanager.autoPause()
}


but then the postDelayed after 1000ms starts the audio playing again.

Answer

Have you tried with:

@Override
public void onPause()
{
  handler.removeCallbacks(Play);
  Soundmanager.autoPause()
}

Ger