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"); }}
Android:在什么情況下出現對話框會導致調用onPause()?
慕婉清6462132
2019-12-17 14:38:30