What does onStart() really do? - Android [duplicate]

拟墨画扇 提交于 2019-12-04 20:00:19
Dimmerg

onStart() is called when activity resumes from stopped state. For example, if you have activity A and starts activity B from it, then activity A will be paused (onPause()) and then stopped (onStop()) and moved to back stack. After this, if you press Back into your activity B, B will be paused(onPause()), stopped (onStop()) and destroyed(onDestroy()), and activity A will be restored from back stack, started (onStart()) and resumed(onResume()). As you can see, system will not call onCreate() for A again.

How to use onStart()? For example, you should unregister listeners for GPS, sensors, etc in onStop() and register again in onStart(). If you register it in onCreate() and unregister in onDestroy(), then GPS service will work always and it will drain battery.

Called when the activity is becoming visible to the user.

Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden.

More: http://developer.android.com/reference/android/app/Activity.html

what i personally do if i want to user onStart , i will assign my listeners (OnclickListener , ... etc ) in the onStart method .

i think really its usless as you could do every thing you want in the onCreate .

Hope that helps

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