android phone screen orientation related issue?
friends,
i am facing an issue related to android phone screen orientation
If i change the orientation of the phone, then it loses the context, if i am in middle of filling a simple form. So, the phone is vertical, I am using soft keyboard, I make it horizontal, so that I can use the keyboard easily again or something else, an开发者_Go百科d kaboom, everything I have entered so far is lost.
any one guide me what is the solution to keep data and state same after changing orientation?
any help would be appriciated.
That's because activity is actually re-created on orientation change. You have to save your state before the change and then restore it. Override onSaveInstanceState to save your data to bundle. The data is then accessible at onCreate (withing the bundle again).
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putSerializable("Key", "Some data"); //put some data
super.onSaveInstanceState(outState);
}
精彩评论