Android活动生命周期 - 这些方法有哪些?

本文翻译自:Android activity life cycle - what are all these methods for?

What is the life cycle of an Android activity? Android活动的生命周期是什么? Why are so many similar sounding methods ( onCreate() , onStart() , onResume() ) called during initialization, and so many others ( onPause() , onStop() , onDestroy() ) called at the end? 为什么在初始化期间调用了如此多的类似声音方法( onCreate()onStart()onResume() )以及最后调用的其他许多其他声明方法( onPause()onStop()onDestroy() )?

When are these methods called, and how should they be used properly? 这些方法何时被调用,它们应该如何正确使用?


#1楼

参考:https://stackoom.com/question/ZjNo/Android活动生命周期-这些方法有哪些


#2楼

ANDROID LIFE-CYCLE ANDROID LIFE-CYCLE

There are seven methods that manage the life cycle of an Android application: 有七种方法可以管理Android应用程序的生命周期:


Answer for what are all these methods for: 回答所有这些方法:

Let us take a simple scenario where knowing in what order these methods are called will help us give a clarity why they are used. 让我们看一个简单的场景,知道调用这些方法的顺序将有助于我们清楚地说明它们的用法。

  • Suppose you are using a calculator app. 假设您使用的是计算器应用程序。 Three methods are called in succession to start the app. 连续调用三种方法来启动应用程序。

onCreate() - - - > onStart() - - - > onResume() onCreate() - - - > onStart() - - - > onResume()

  • When I am using the calculator app, suddenly a call comes the. 当我使用计算器应用程序时,突然有一个电话来了。 The calculator activity goes to the background and another activity say. 计算器活动转到后台,另一个活动说。 Dealing with the call comes to the foreground, and now two methods are called in succession. 处理呼叫到达前台,现在连续调用两个方法。

onPause() - - - > onStop() onPause() - - - > onStop()

  • Now say I finish the conversation on the phone, the calculator activity comes to foreground from the background, so three methods are called in succession. 现在说我在电话上完成了对话,计算器活动从后台开始变为前景,因此连续调用了三种方法。
<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值