How to pause an activity on the emulator without stoping it

1k views Asked by At

My question is almost similar to this question. In my app when I press the home button my app is stopped and not only paused. After reading the answers in the question (given in the link) I realized that onPause and onStop is indeed called after pressing the home button. So my question is how do I pause my activity on the emulator( there is no lock screen button) without stopping it or doing it programmitically.My logcat details are :

  06-24 05:43:29.011: D/My(1689): OnCreate
  06-24 05:43:29.011: D/My(1689): OnResume
  06-24 05:43:34.251: D/Sng[0](1689): /storage/sdcard/Music/05.Only you.mp3
  06-24 05:43:34.771: E/MediaPlayer(1689): Should have subtitle controller already set
  06-24 05:43:41.691: D/My(1689): OnPause
  06-24 05:43:48.081: D/My(1689): OnStop
2

There are 2 answers

6
Ihor Bykov On BEST ANSWER

Activity will be paused, for example, when dialog will appear. From Android Dev:

When the system calls onPause() for your activity, it technically means your activity is still partially visible

0
Luis404 On

create a alertdialog in your activity when in onResume()(or press a button)

    // 1. Instantiate an AlertDialog.Builder with its constructor
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    // 2. Chain together various setter methods to set the dialog characteristics
    builder.setMessage(R.string.dialog_message)
           .setTitle(R.string.dialog_title);

    // 3. Get the AlertDialog from create()

AlertDialog dialog = builder.create();
dialog.show()