Android Java: Understanding Activity Life?

When you start new activity from your current activity then there are two possibility of your current activity.

Up vote 0 down vote favorite share g+ share fb share tw.

I'm new to android development and I get how the android has an activity life. If I have an app and I press a button to use the phone's camera funcationality like so... public void onClick(View v) { // TODO Auto-generated method stub Intent cameraIntent = new Intent(android.provider.MediaStore. ACTION_VIDEO_CAPTURE); startActivityForResult(cameraIntent, CAMERA_VIDEO_REQUEST); } How does onPause() or onDestroy() and the other stuff work?

I have this outside the onCreate() protected void onPause(){ super.onPause(); } If I want to press the back button or press the home button, do I have to destroy or pause the camera function? If so, I'm still trying to figure out how to do so? Thanks!

Java android activity android-activity link|improve this question asked Feb 23 at 3:44andrewliu642211 66% accept rate.

While you are new to Android, it may even be useful to add simple Logging statements for the various lifecycle methods just to quickly obtain info about what is going on behind the scenes as you interact with the app... onPause will always be called before onStop. – mastDrinkNimbuPani Feb 23 at 4:24.

When you start new activity from your current activity then there are two possibility of your current activity Pause Stop Paused: Another activity is in the foreground and has focus, but this one is still visible. That is, another activity is visible on top of this one and that activity is partially transparent or doesn't cover the entire screen. A paused activity is completely alive (the Activity object is retained in memory, it maintains all state and member information, and remains attached to the window manager), but can be killed by the system in extremely low memory situations.

Stopped: The activity is completely obscured by another activity (the activity is now in the "background"). A stopped activity is also still alive (the Activity object is retained in memory, it maintains all state and member information, but is not attached to the window manager). However, it is no longer visible to the user and it can be killed by the system when memory is needed elsewhere.

For example you are starting the Camera activity from your activity then your current activity will be Stop because the Camera activity will covers all your screen and your activity is not visible to camera activity. Here is the complete description. You are starting the Camera activity using the Intent so you do not have to handle the call back methods of the camera activity.

System will manage the call back method you do not have to manage it. You just have to manage the Activity result which you will get in your activity from the Camera activity. EDIT And also ob course you never have to directly call any life cycle methods of the Activity.

System automatically calls this method according to activity state. You just have to write your implementation in this methods to do your work.

This is a good answer. I would only add that you never have to directly call any life cycle methods. – Nick Campion Feb 23 at 4:01 @NickCampion Yeah I have updated my answer.

– Dharmendra Feb 23 at 4:05 sweet thanks! It explains a lot! – andrewliu Feb 23 at 6:05.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions