hellomello
hellomello

Reputation: 8597

Android Java: Understanding Activity Life?

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!

Upvotes: 0

Views: 206

Answers (1)

Dharmendra
Dharmendra

Reputation: 34026

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.

Upvotes: 1

Related Questions