質問

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.

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top