Data loss while spinning screen

Asked

Viewed 41 times

0

I’m developing an Android APP, in it you type some values in Edittext. But when you turn the phone to change the orientation the Edittext data is lost. How do I resolve?

  • Hi Leandro. Post your code so we can help

1 answer

1

Use put methods to store values in onSaveInstanceState:

protected void onSaveInstanceState(Bundle extra) {
  super.onSaveInstanceState(extra);
  extra.putString("text", "your text here");
}

And restore in onCreate:

public void onCreate(Bundle extra) {
  if (extra != null) {
    String value = extra.getString("text");
  }
}

Finally, remove from the manifest android:configChanges="orientation|keyboardHidden"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.