简体   繁体   中英

Activity Life Cycle Method

Name the method that gets called when another Activity comes to foreground and when Current Activity Comes to Foreground. (The methods in both cases to be mentioned relate to the current activity)

Go through this you will understand the activity lifecycle.

public class MainActivity extends Activity {
String msg = "Android : ";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  Log.d(msg, "The onCreate() event");
}

/** Called when the activity is about to become visible. */
@Override
protected void onStart() {
  super.onStart();
  Log.d(msg, "The onStart() event");
}

/** Called when the activity has become visible. */
@Override
protected void onResume() {
  super.onResume();
  Log.d(msg, "The onResume() event");
}

/** Called when another activity is taking focus. */
@Override
protected void onPause() {
  super.onPause();
  Log.d(msg, "The onPause() event");
}

/** Called when the activity is no longer visible. */
@Override
protected void onStop() {
  super.onStop();
  Log.d(msg, "The onStop() event");
}

/** Called just before the activity is destroyed. */
@Override
public void onDestroy() {
  super.onDestroy();
  Log.d(msg, "The onDestroy() event");
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM