Android 活动生命周期:新活动开始时的状态顺序 [英] Android activity lifecycle: state order when new activity starts

查看:32
本文介绍了Android 活动生命周期:新活动开始时的状态顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我通过这种方式从 Activity1 启动 Activity2:startActivity(Activity2); 先执行什么:onStop() (Activity1) 或 onStart() (Activity2) ?

If I launch Activity2 from Activity1 by this way: startActivity(Activity2); what executes first: onStop() (Activity1) or onStart() (Activity2) ?

它们是同时工作还是轮流工作?如果一个接着一个,什么是第一?

Do they work simultaneously or in turn? If one after another, what is first?

所以一般来说:如果这个顺序存在,那么第一个活动第二个开始时活动的状态顺序是什么?

So in general : what is the activity's state order when first activity starts second, if this order exists?

推荐答案

关键是了解活动是如何开始的.当您在 startActivity() 方法中发布 Intent 时,您只需要求系统启动此活动.接下来系统尝试启动 Activity2 并向 Activity1 发送消息.顺序是不确定的,在不同的情况下可能会有所不同.

The key is understanding how activity is started. When you publish Intent in startActivity() method you just ask system to start this activity. Next system try to start Activity2 and sends message to Activity1. Order is undetermined and can be different in different situations.

当两个活动都在同一个流程(应用程序)中工作时,我的回答似乎是错误的正如 Daniil Popov 指出的:https://developer.android.com/guide/components/activities/activity-lifecycle.html(协调活动部分)

Looks like my anwer was wrong for situation when both activities works within this same process (app) As pointed Daniil Popov: https://developer.android.com/guide/components/activities/activity-lifecycle.html (Coordinating activities section)

这篇关于Android 活动生命周期:新活动开始时的状态顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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