如何暂停模拟器上的活动而不停止它

时间:2015-06-24 09:48:11

标签: android onpause android-homebutton

我的问题与this question几乎相似。在我的应用程序中,当我按下主页按钮时,我的应用程序停止了,不仅暂停了。在阅读问题中的答案后(链接中给出),我意识到在按下主页按钮后确实调用了onPause和onStop。所以我的问题是如何暂停我在模拟器上的活动(没有锁定屏幕按钮)而不停止它或按程序执行。我的logcat详细信息是:

  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 个答案:

答案 0 :(得分:1)

活动将暂停,例如,当dialog出现时。 来自Android Dev:

当系统为您的活动调用onPause()时,从技术上讲,这意味着您的活动仍然部分可见

答案 1 :(得分:0)

在onResume()(或按下按钮)时,在您的活动中创建一个alertdialog

    // 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()
相关问题