屏幕切换
android切屏生命周期:
http://marshal.easymorse.com/archives/2056
禁止切屏时调用oncreate,onstop,onresume
如果在androidmanifest.xml中加入配置
android:configChanges="orientation|keyboardHidden|navigation
当屏幕翻转时,Activity就不会重复的调用onCreate()、onPause()和onResume().
而是调用onConfigurationChanged(Configuration newConfig)
http://stulog.com/?post=214
在android官方文档中指出另一种保存数据的方法:
The Activity class has a special method called onRetainNonConfigurationInstance(). This method can be used to pass an arbitrary object your future self and Android is smart enough to call this method only when needed. In the case of Photostream, the application used this method to pass the downloaded images to the future activity on orientation change. The implementation can be summarized like so:
private void loadPhotos() { final Object data = getLastNonConfigurationInstance(); // The activity is starting for the first time, load the photos from Flickr if (data == null) { mTask = new GetPhotoListTask().execute(mCurrentPage); } else { // The activity was destroyed/created automatically, populate the grid // of photos with the images loaded by the previous activity final LoadedPhoto[] photos = (LoadedPhoto[]) data; for (LoadedPhoto photo : photos) { addPhoto(photo); } }}