Understanding Android Activity Life Cycle

NewImage

 

Activity is a single screen with user interface in Android just like a window form in visual .net development tools. Just like C++ which start with main() function. Android start its activity with onCreate() method. This is where you should do all of your  create views, bind data to lists, etc. OnStart() is call when the activity is visible to the user. OnResume() is call when the user start interacting with the apps. OnPause() is called when the app cannot receive any user input or execute code. OnStop() is called when the The activity is no longer visible to the user. onDestroy() is called before the activity is being destroy by the system.

 

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import androidrich.com.firebaseauthtest.R;

public class TestActivity extends Activity {
/** Called when the activity is first created. */

private final static String TAG = "TestActivity";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i(TAG, "On Create .....");
}
/* (non-Javadoc)
* @see android.app.Activity#onDestroy()
*/
@Override
protected void onDestroy() {
super.onDestroy();
Log.i(TAG, "On Destroy .....");
}
/* (non-Javadoc)
* @see android.app.Activity#onPause()
*/
@Override
protected void onPause() {
super.onPause();
Log.i(TAG, "On Pause .....");
}

/* (non-Javadoc)
* @see android.app.Activity#onRestart()
*/
@Override
protected void onRestart() {
super.onRestart();
Log.i(TAG, "On Restart .....");
}

/* (non-Javadoc)
* @see android.app.Activity#onResume()
*/
@Override
protected void onResume() {
super.onResume();
Log.i(TAG, "On Resume .....");
}

/* (non-Javadoc)
* @see android.app.Activity#onStart()
*/
@Override
protected void onStart() {
super.onStart();
Log.i(TAG, "On Start .....");
}
/* (non-Javadoc)
* @see android.app.Activity#onStop()
*/
@Override
protected void onStop() {
super.onStop();
Log.i(TAG, "On Stop .....");
}
}

No comments:

Post a Comment