Android Activity Lifecycle
Android Activity Lifecycle is controlled by 7 methods of android.app.Activity class. The android Activity is the subclass of ContextThemeWrapper class.
An activity is the single screen in android. It is like window or frame of Java.
there are some type pf methods .
onCreate-called when activity is first created.
onStart-called when activity is becoming visible to the user.
onResume-called when activity will start interacting with the user.
onPause-called when activity is not visible to the user.
onStop-called when activity is no longer visible to the user.
onRestart-called after your activity is stopped, prior to start.
onDestroy-called before the activity is destroyed.
- package com.vinodsonava.activitylifecycle;
- import android.os.Bundle;
- import android.app.Activity;
- import android.util.Log;
- import android.view.Menu;
- public class MainActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Log.d("lifecycle","onCreate invoked");
- }
- @Override
- protected void onStart() {
- super.onStart();
- Log.d("lifecycle","onStart invoked");
- }
- @Override
- protected void onResume() {
- super.onResume();
- Log.d("lifecycle","onResume invoked");
- }
- @Override
- protected void onPause() {
- super.onPause();
- Log.d("lifecycle","onPause invoked");
- }
- @Override
- protected void onStop() {
- super.onStop();
- Log.d("lifecycle","onStop invoked");
- }
- @Override
- protected void onRestart() {
- super.onRestart();
- Log.d("lifecycle","onRestart invoked");
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- Log.d("lifecycle","onDestroy invoked");
- }
- }
|
Good for Helpful for me and good to learn for beginners
ReplyDeleteThanks
Ravi kumar