我正在测试这段代码,它显示了活动处于哪个状态
public class Activity101Activity extends Activity {
String tag = "Lifecycle";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
setContentView(R.layout.activity_activity101);
Log.d(tag , "In the onCreate() event");
}
public void onStart()
{
super.onStart();
Log.d(tag , "In the onStart() event");
}
public void onRestart()
{
super.onRestart();
Log.d(tag , "In the onRestart() event");
}
public void onResume()
{
super.onResume();
Log.d(tag , "In the onResume() event");
}
public void onPause()
{
super.onPause();
Log.d(tag , "In the onPause() event");
}
public void onStop()
{
super.onStop();
Log.d(tag , "In the onStop() event" );
}
public void onDestroy()
{
super.onDestroy();
Log.d(tag , "In the onDestroy() event");
}
}
所以我看到 onDestroy() 仅在活动在屏幕上时按下后退按钮时才会被调用,否则永远不会被调用。因此,如果我在活动运行时按下主页按钮,它应该在后台运行。但是,如果我去,Settings -> Apps -> Running
我无法在列表中看到它。那么这是否意味着它是否在后台运行?
再一次,再一次,这段代码显示 onPause() 总是跟在 onStop() 之后,而 onStart() 总是跟在 onResume() 之后。那么为什么它们在Android环境中被定义为不同的功能而不是组合呢?