在活动生命周期调用在下列情况下用什么方法: [英] What methods are invoked in the Activity Lifecycle in the following cases:

查看:149
本文介绍了在活动生命周期调用在下列情况下用什么方法:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个Hello World单个活动的应用程序。我开始这个应用程序。

Let's say I have a Hello World single Activity application. I start this application.

在每一种情况下调用什么样的方法:

What methods are invoked in each case:

  • 在Home键是pressed:
    后退按钮是pressed:
    电话呼叫中接收到:
  • Home button is pressed: ?
    Back button is pressed: ?
    Phone call is received: ?

一旦用户通过应用程序图标重新启动应用程序被调用什么方法(假设操作系统已经没有了其他应用程序需要的内存条件):

What methods are invoked once the user starts the application again via the app icon (assuming the OS hasn't had a "other apps need memory condition"):

  • 在Home键为pressed:
    后退按钮是pressed:
    接收电话呼叫:
  • Home button was pressed: ?
    Back button was pressed: ?
    Phone call was received: ?

谢谢大家。

编辑:附加题:用户如何调用的onPause ,而不必调用的onStop

Extra Credit: How can the user invoke onPause without invoking onStop?

推荐答案

这两个pressing home键和接听电话不删除该任务的堆栈中的活动,并将于当你再次进入程序=>的onPause()=>的onStop()。

both pressing home button and receiving a call don't remove the activity from the task's stack, and will be available when you re-enter the app => onPause() => onStop().

作为活动周期图的表演,再进入应用程序调用=> onRestart()=> ONSTART()=> onResume()

as the activity lifecycle diagram shows, re-entering the app calls => onRestart() => onStart() => onResume()

pressing后退按钮,而不是杀死活性=>的onPause()=>的onStop()=>的onDestroy()

pressing the back button instead kills the activity => onPause() => onStop() => onDestroy()

重新输入在这种情况下,应用程序调用的经典=>的onCreate()=> ONSTART()=> onResume()

re-entering the app in this case calls the classics => onCreate() => onStart() => onResume()

修改

从的http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

如果活动已经失去焦点,但   仍然可见(即,一个新的   非全尺寸或透明的活动   一直专注于你的活动的顶部),它   已暂停。一个暂停活动   完全活(它维护所有   状态和成员信息和   保持附着到窗   经理),但是可以由被杀死   系统在极端的低内存   的情况。

If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations.

这篇关于在活动生命周期调用在下列情况下用什么方法:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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