Why is onResume() called when an activity starts?

拥有回忆 提交于 2019-11-30 07:34:16

Well i do not understand very well what you are trying to ask or what is the question here. BUT i will recommend you to read the "Android Activity LifeCycle" and that will clear many of your doubts cause in android is not the same as other languages or platforms.

Note: The OnResume is call each time the activity is "visible", so as many times as your activity becomes visible, the same number of times your method will be called. If you just want to call the method the first time, then the OnCreate is what your looking for.

Please take a look at the activity lifecycle state chart.

This is the order the methods are being called:

  1. onCreate()
  2. onStart()
  3. onResume()
  4. -> activity is running

http://developer.android.com/reference/android/app/Activity.html#ProcessLifecycle

onResume after onCreate is the normal Activity Lifecycle

The reason you get onStart and onResume called even on the first launch is that it makes writing code easier.

You can assume that before you return to onResume you will get onPause called since there is no way to exit the "resumed" state without onPause. That behavior can be used to initialize things in onResume and to de-initialize them without further checking in onPause. If you can't be sure that onResume was called at the start that whole scheme breaks.

On a sidenote: Don't access your database from any of the onXYZ methods since that will block the UI thread which should rather draw the UI and handle touch events.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!