简体   繁体   English

Android Activity生命周期:onStart() - > onStop()可能吗?

[英]Android Activity Lifecycle: onStart() -> onStop() possible?

In the Android Application Fundamentals it says that after the call to the onStart()-method of the activity lifecycle either the callback method onResume() or onStop() is called. Android应用程序基础知识中,它表示在调用onStart() - 活动生命周期的方法之后,调用onResume()onStop()的回调方法。 In case of an "normal" Start of an activity the system calls onCreate() , onStart() , onResume() . 在“正常”活动开始的情况下,系统调用onCreate()onStart()onResume() But does somebody know an example where onStart() - onStop() are executed one after another? 但有人知道onStart() - onStop()一个接一个地执行的例子吗?

  1. From your activity, start another activity that is not full-screen (for example give it android:theme="@android:style/Theme.Dialog"). 从你的活动,开始另一个不是全屏的活动(例如给它android:theme =“@ android:style / Theme.Dialog”)。

    At this point your first activity has had onPause() called but not onStop() because it is not in the front but still visible. 此时,您的第一个活动已调用onPause()而不是onStop(),因为它不在前面但仍然可见。

  2. Press home. 按回家。

    At this point onStop() is called for your first activity. 此时,onStop()将被调用为您的第一个活动。

  3. Relaunch your app. 重新启动您的应用。

    At this point onStart() is called for your first activity, but not onResume() because it still has the non-full-screen activity on top of it. 此时onStart()被调用用于您的第一个活动,但不是onResume(),因为它仍然具有非全屏活动。

  4. Press home. 按回家。

    At this point onStop() is called on the first activity, without having gone through onResume(). 此时onStop()在第一个活动上被调用,而没有通过onResume()。

When the user leaves your activity, the system calls onStop() to stop the activity 当用户离开您的活动时,系统会调用onStop()来停止活动
(1). (1)。 If the user returns while the activity is stopped, the system calls onRestart() 如果用户在活动停止时返回,则系统调用onRestart()
(2), quickly followed by onStart() (2),紧接着onStart()
(3) and onResume() (3)和onResume()
(4). (4)。 Notice that no matter what scenario causes the activity to stop, the system always calls onPause() before calling 请注意,无论何种情况导致活动停止,系统始终在调用之前调用onPause()

According to the flowchart on the page provided, it is not possible for onStop() to be called without onResume() being called. 根据提供的页面上的流程图​​,如果没有调用onResume() ,则无法onStop() I could think of some potential scenario in which the system shuts down the application in the middle of starting it up, but I have no clue what or how such a scenario would be triggered, or if it even exists. 我可以想一下系统在启动过程中关闭应用程序的一些潜在场景,但我不知道触发这样的场景是什么或如何,或者它是否存在。

As pointed out by Tseng, it's possible that a task will never be brought to the foreground (I'm thinking of say, the task that syncs the phone with an Exchange server). 正如Tseng所指出的那样,任务永远不会被带到前台(我想是将手机与Exchange服务器同步的任务)。 I imagine Such a task will never have onResume() or onPause() called. 我想这样的任务永远不会有onResume()onPause()调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android活动生命周期:onResume(),onStart(),onPause()和onStop()上的工作负载 - Android Activity LifeCycle: Workload on onResume(), onStart(), onPause() and onStop() Android生命周期:在onStart()或onResume()中填写活动中的数据? - Android lifecycle: Fill in data in activity in onStart() or onResume()? Android:在活动的onStart(),onStop(),onDestroy()的开头或结尾调用super()? - Android: Call super() at the beginning or end of onStart(), onStop(), onDestroy() in activity? 贯穿多个onStart和onStop周期的Android活动意图 - Android- activity intents living through multiple onStart and onStop cycles 有没有办法配置 android 应用程序以接收 onStart 和 onStop 之间的活动结果? - Is there a way to configure android app to receive activity result between onStart and onStop? Android Firebase onStart和onStop的说明 - Android firebase onStart and onStop explanation android:何时使用onStart(),onStop()? - android: when to use onStart(), onStop()? Android活动生命周期-在onStop()之后和调用onDestory()时会发生什么 - Android activity lifecycle - what happens after onStop() and when onDestory() is called 没有onStart和onStop + Google Analytics(分析)的活动 - Activity without onStart and onStop + Google Analytics 在onStop之前调用新Activity的onStart - onStart of new Activity is called before onStop of parent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM