Android弹窗不走onpause方法,Android:在什么情况下出现对话框会导致调用onPause()?...

Android Activities文档中的一个片段(向下滚动到“ 前台寿命 ”行)说:

活动可以频繁地切换到前台和从前台跳出,例如,onPause()当设备进入睡眠状态或出现对话框时,将调用该活动。

我不太明白这一点。在什么情况下会发生这种情况?被onPause()称为仅如果有问题的对话的上下文是从顶部其活性的对话框将显示不同?

编辑:添加代码示例以详细说明我的疑问

根据文档中的上述引用,onPause()当显示以下代码中的AlertDialog(或只是Dialog)时,是否应该调用我的活动的方法?显示对话框时,我是否应该看到“ onPause named”日志条目?

但我看不到这种情况。如果我正确理解了Android的生命周期,那么也不应该!那么,当时的文件指向什么呢?

public class LifeCycleTestActivity extends Activity {

private static final String TAG = "LifeCycleTest";

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button btn = (Button) findViewById(R.id.button1);

btn.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

Log.d(TAG, "onClick");

AlertDialog dialog = new AlertDialog.Builder(LifeCycleTestActivity.this).create();

dialog.setMessage("You Clicked on the button");

dialog.setTitle("Dialog!");

dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

dialog.dismiss();

}

});

dialog.setCancelable(true);

dialog.show();

/*

Dialog dialog = new Dialog(LifeCycleTestActivity.this);

dialog.setTitle("Dialog!");

dialog.setCancelable(true);

dialog.show();

*/

}

});

}

@Override

protected void onPause() {

Log.d(TAG, "onPause() called");

super.onPause();

}

@Override

protected void onResume() {

super.onResume();

Log.d(TAG, "onResume() called");

}

}