mherzl
mherzl

Reputation: 6220

In the android code base, where is the activity lifecycle defined?

I see this documentation under developer.android.com, describing the Activity lifecycle. However, I am trying to match the description up with the actual android code, at cs.android.com, where the activity life cycle is actually defined.

Looking there in code search at Activity.java, I see, for example, the onCreate method defined. But I have not been able to find where this is actually called as part of the lifecycle. Maybe it is listed when I search for its references, but there are thousands of references, including a lot of overrides, and I have not found where it is called defining its place in the activity life cycle.

Where might I find that?

Upvotes: 0

Views: 41

Answers (1)

Hamzeh
Hamzeh

Reputation: 26

Copy the below code to your main activity and run it while opening the logcat .The log massage will show you which method within the activity cycle has been called .

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Log.v("MainActivity", "Oncreat");
}

@Override
protected void onStart() {
    super.onStart();
    Log.v("MainActivity", "onStart");
}

@Override
protected void onResume() {
    super.onResume();
    Log.v("MainActivity", "onResume");
}

@Override
protected void onPause() {
    super.onPause();
    Log.v("MainActivity", "onPause");
}

@Override
protected void onStop() {
    super.onStop();
    Log.v("MainActivity", "onStop");
}

@Override
protected void onRestart() {
    super.onRestart();

    Log.v("MainActivity", "OnRestart");

}

@Override
protected void onDestroy() {
    super.onDestroy();
    Log.v("MainActivity", "onDestroy");
}

You can also check this link for more details .

Upvotes: 1

Related Questions