Java 活动生命周期Android Studio
我最近研究了活动生命周期,对此我有一些疑问,以下是它们Java 活动生命周期Android Studio,java,android,android-studio,Java,Android,Android Studio,我最近研究了活动生命周期,对此我有一些疑问,以下是它们 这是密码。 表示android生命周期回调 onCreate,onRestoreSavedInstanceState和onSavedInstanceState TextView textView; // some transient state for the activity instance String gameState; @Override public void onCreate(Bundle savedInstanceS
这是密码。
表示android生命周期回调
onCreate
,onRestoreSavedInstanceState
和onSavedInstanceState
TextView textView;
// some transient state for the activity instance
String gameState;
@Override
public void onCreate(Bundle savedInstanceState) {
// call the super class onCreate to complete the creation of activity like
// the view hierarchy
super.onCreate(savedInstanceState);
// recovering the instance state
if (savedInstanceState != null) {
gameState = savedInstanceState.getString(GAME_STATE_KEY);
}
// set the user interface layout for this activity
// the layout file is defined in the project res/layout/main_activity.xml file
setContentView(R.layout.main_activity);
// initialize member TextView so we can manipulate it later
textView = (TextView) findViewById(R.id.text_view);
}
// This callback is called only when there is a saved instance that is previously saved by using
// onSaveInstanceState(). We restore some state in onCreate(), while we can optionally restore
// other state here, possibly usable after onStart() has completed.
// The savedInstanceState Bundle is same as the one used in onCreate().
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
textView.setText(savedInstanceState.getString(TEXT_VIEW_KEY));
}
// invoked when the activity may be temporarily destroyed, save the instance state here
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putString(GAME_STATE_KEY, gameState);
outState.putString(TEXT_VIEW_KEY, textView.getText());
// call superclass to save any view hierarchy
super.onSaveInstanceState(outState);
}
在这里,在OnSaveInstanceState(Bundle outState)
方法中,为什么超级调用在末尾,为什么函数原型不是这个OnSaveInstanceState(@NonNull Bundle outState)
。
如果原型是
onSaveInstanceState(@NonNull Bundle outState)
,会发生什么