android onresume时view,android – 当对话框出现时不调用OnResume
An activity can frequently transition in and out of the
foreground—for example, onPause() is called when the device goes to
sleep or when a dialog appears.
我有一個帶按鈕的活動.當我點擊按鈕時會出現(xiàn)一個對話框.我期望在對話框出現(xiàn)時調用onPause方法,然后在關閉對話框時調用onResume方法.但沒有一個被稱為.
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MyDialog myDialog = new MyDialog();
myDialog.show(getFragmentManager(),myDialog.TAG);
}
});
@Override
protected void onResume() {
super.onResume();
Toast.makeText(this,"ON RESUME ACTIVITY",Toast.LENGTH_SHORT).show();
}
@Override
protected void onPause() {
super.onPause();
Toast.makeText(this,"ON PAUSE ACTIVITY",Toast.LENGTH_SHORT).show();
}
有誰知道為什么這些方法沒有被調用?
謝謝
解決方法:
Dialog也是您的活動UI窗口的一部分.所以onPause()&當您顯示或隱藏對話框時,不會調用onResume().
如果你想要onPause()&顯示/隱藏對話框時調用onResume(),然后在單獨的活動中顯示該對話框UI,并將該活動作為對話框啟動.
標簽:android,android-activity,lifecycle
來源: https://codeday.me/bug/20190824/1709085.html
總結
以上是生活随笔為你收集整理的android onresume时view,android – 当对话框出现时不调用OnResume的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 设置view亮度,and
- 下一篇: 华为路由器 android,华为智能路由