不寻常的 android activity 生命周期
Unusual android activity lifecycle
我写了一个游戏,在市场日志中我有时会看到以下模式:
06:02:13:835|INFO|1|MainActivity|MainActivity#2.OnCreate
06:02:13:932|INFO|1|MainActivity|MainActivity#2.OnStart
06:02:14:010|INFO|1|MainActivity|MainActivity#2.OnResume
...
06:09:27:688|INFO|1|MainActivity|MainActivity#2.OnPause
06:09:28:895|INFO|1|MainActivity|MainActivity#3.OnCreate
06:09:29:159|INFO|1|MainActivity|MainActivity#3.OnStart
06:09:29:319|INFO|1|MainActivity|MainActivity#3.OnResume
06:09:29:551|INFO|1|MainActivity|MainActivity#2.OnStop
06:09:29:596|INFO|1|MainActivity|MainActivity#2.OnDestroy
MainActivity 实例#3 在 MainActivity 实例#2 被销毁之前创建并启动。这个模式是什么意思?为什么新实例在前一个实例被销毁之前启动?
显然我不会手动创建 activity。用户只需点击图标即可开始游戏(至少我希望如此)。
Activity 具有单任务启动模式。
谢谢!
不保证会调用 onDestroy 回调。来自 docs:
onDestroy() = The final call you receive before your activity is
destroyed. This can happen either because the activity is finishing
(someone called finish() on it, or because the system is temporarily
destroying this instance of the activity to save space. You can
distinguish between these two scenarios with the isFinishing() method.
假设您的应用程序有两个活动。那么这就是生命周期
onDestroy 如果您显式调用 finish() 将被调用;你自己或者喜欢这个例子,如果你按下后退按钮,因为按下后退键实际上会在你的 activity 上触发 finish() 方法,它会导致你的 activity 被暂停->停止->销毁
我写了一个游戏,在市场日志中我有时会看到以下模式:
06:02:13:835|INFO|1|MainActivity|MainActivity#2.OnCreate
06:02:13:932|INFO|1|MainActivity|MainActivity#2.OnStart
06:02:14:010|INFO|1|MainActivity|MainActivity#2.OnResume
...
06:09:27:688|INFO|1|MainActivity|MainActivity#2.OnPause
06:09:28:895|INFO|1|MainActivity|MainActivity#3.OnCreate
06:09:29:159|INFO|1|MainActivity|MainActivity#3.OnStart
06:09:29:319|INFO|1|MainActivity|MainActivity#3.OnResume
06:09:29:551|INFO|1|MainActivity|MainActivity#2.OnStop
06:09:29:596|INFO|1|MainActivity|MainActivity#2.OnDestroy
MainActivity 实例#3 在 MainActivity 实例#2 被销毁之前创建并启动。这个模式是什么意思?为什么新实例在前一个实例被销毁之前启动?
显然我不会手动创建 activity。用户只需点击图标即可开始游戏(至少我希望如此)。
Activity 具有单任务启动模式。
谢谢!
不保证会调用 onDestroy 回调。来自 docs:
onDestroy() = The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.
假设您的应用程序有两个活动。那么这就是生命周期
onDestroy 如果您显式调用 finish() 将被调用;你自己或者喜欢这个例子,如果你按下后退按钮,因为按下后退键实际上会在你的 activity 上触发 finish() 方法,它会导致你的 activity 被暂停->停止->销毁