我有很多字段应该在Activity中保存/恢复。
private int mPrevRdbDayId;
private ScrollView mScrView;
private TextView mTxtTitleFirst;
private TextView mTxtTitleSecond;
private TextView mTxtTitleCoin;
private ImageView mImgBackground;
private View mLoutColor;
private TextView mTxtTime;
private RadioGroup mRdgDay;
private RadioButton mRdbOtherDay;
private RadioGroup mRdgPrivacy;
private View mLoutFriends;
private EditText mEdtAddTxt;
private TextView mTxtAddMedia;
private TextView mTxtAddMap;
private SeekBar mSkbTime;
private View mLoutMap;
private GoogleMap mMap;
private FeedItem mFeedItem;
private RecyclerView mRvMedia;
private TextView mTxtMapPlace;
private TextView mTxtMapAddress;
private RecyclerView mRvRecipients;
private RecipientRecyclerAdapter mRvRecipientsAdapter;
private RecyclerLoader mRvFriends;
private List<ImageItem> mListMedia;
private List<ImageItem> mListPrepareVideo;
所以我应该保存这样的一切:
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("mPrevRdbDayId", mPrevRdbDayId);
....... and same for each field
Log.d(LOG_TAG, "onSaveInstanceState");
}
然后对于onRestoreInstanceState也一样,这似乎是方法中的boilplate代码。是否有适当的模式来处理这种情况? Thx提前。