Android studio Activity Lifecycle
Today is learn Android studio Activity Lifecycle Follow This Tutorial.
1.Created – Activity is created
2.Running – Activity is visible and interacts with the user
3.Paused -Activity is still visible but partially obscured, instance is running but might be killed by the system.
4.Stopped – Activity is not visible, instance is running but might be killed by the system.
5.Destroyed -Activity has been terminated by the system of by a call to its finish() method.
1.Main Activity:
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
@SuppressLint("NewApi")
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
notify("onCreate");
}
@Override
protected void onPause() {
super.onPause();
notify("onPause");
}
@Override
protected void onResume() {
super.onResume();
notify("onResume");
}
@Override
protected void onStop() {
super.onStop();
notify("onStop");
}
@Override
protected void onDestroy() {
super.onDestroy();
notify("onDestroy");
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
notify("onRestoreInstanceState");
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
notify("onSaveInstanceState");
}
private void notify(String methodName) {
String name = this.getClass().getName();
String[] strings = name.split("\\.");
Toast.makeText(getApplicationContext(),
methodName + "" + strings[strings.length - 1],
Toast.LENGTH_LONG).show();
}
}
No comments:
Post a Comment