如何强制从周期到的onPause onResume

编程入门 行业动态 更新时间:2024-10-23 13:27:04
本文介绍了如何强制从周期到的onPause onResume的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图迫使我的Andr​​oid应用程序从的onPause方法是直接用对话进入onResume方法。

I am trying to force my Android application to go from the onPause method directly to the onResume method by using a dialog.

我在我FirstActivity类onClick的方法,实现OnClickListener以下code:

I have the following code in the onClick method in my FirstActivity class which implements OnClickListener:

Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.newlayout); dialog.setTitle("This is my custom dialog box"); dialog.setCancelable(true); dialog.show();

我已经设置了每个生命周期的方法来打印出日志信息时,Android应用进入每种方法:

I've set up each lifecycle method to print out a log message when the Android app enters each method:

Log.i(ActivityName, " onCreate"); Log.i(ActivityName, " onPause"); Log.i(ActivityName, " onResume");

和等..

当我点击我的按钮显示对话框,对话框显示出来就好了,但我没有收到显示对话框时的onPause被调用的任何日志消息,我没有收到任何日志消息的onResume按下返回按钮时,我的手机上退出对话框被调用的方法。

When I click my button to show the dialog, the dialog shows up just fine, but I do not receive any log messages that the onPause is being called when showing the dialog and I'm not receiving any log messages that the onResume method is being called when pushing the "back" button on my phone to exit the dialog.

我在做什么错了?

推荐答案

A 对话框总是会创建并显示为活动的一部分(看看这篇文章在对话框)。这就是为什么你的活动方法 onResume 和的onPause 不叫。当对话框显示你的活动仍处于运行状态。

A Dialog is always created and displayed as a part of an Activity(take a look at this article on Dialogs). That's why your Activity methods onResume and onPause are not called. When a Dialog is displayed your Activity is still in running state.

更多推荐

如何强制从周期到的onPause onResume

本文发布于:2023-11-30 15:02:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:周期   onPause   onResume

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!