
上QQ阅读APP看书,第一时间看更新
There's more...
The onRestoreInstanceState() callback is not the only place where the state can be restored. Look at the signature of onCreate():
onCreate(Bundle savedInstanceState)
Both methods receive the same Bundle instance named savedInstanceState. You could move the restore code to the onCreate() method and it would work the same. But one catch is that the savedInstanceState bundle will be null if there is no data, such as during the initial creation of the activity. If you want to move the code from the onRestoreInstanceState() callback, just check to make sure that the data is not null. Here's how that code would look:
if (savedInstanceState!=null) { mCounter = savedInstanceState.getInt(KEY_COUNTER); }