如何强制从周期到的onPause onResume [英] How to force lifecycle from onPause to onResume

查看:335
本文介绍了如何强制从周期到的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆