-1

I created a button, now i want that if I click on it, my app does a pause till I click again then it should resume at the same point. I've tried to use onPause() but it hasn't any effect for my app.

   @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (isChecked) {

        Method should be paused!

    } else {

        Method should be resumed!
    }

}

I've a method which has an TTS and an timecounter. Now i want to add a pause/resume button. I have no idea how I can handle it.

basti12354
  • 2,490
  • 4
  • 24
  • 43
  • Basically what Libin said in their answer. You cannot force the pausing of an `Activity` or force resuming it by calling the life-cycle methods. Those methods are called by the Android OS as part of the `Activity` life-cycle. – Squonk Mar 24 '14 at 23:54

1 Answers1

3

You have to understand how activity life cycle works. Please read android manual. You can't call onPause/onResume an activity directly

onPause : Called when the system is about to start resuming a previous activity. This is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, etc.

onResume : Called when the activity will start interacting with the user.

Please read http://developer.android.com/reference/android/app/Activity.html

Libin
  • 16,967
  • 7
  • 61
  • 83
  • what is your requirement? – Libin Mar 24 '14 at 23:53
  • There runs a method with exercise like sit-ups, I use in this method TTS and a for-loop to count how long i have to do the exercise. Now I want to add a button to pause the exercise and resume it. – basti12354 Mar 25 '14 at 00:00