Search code examples
androidandroid-intentandroid-orientation

Android: How to retain my intent open on screen change


From my main activity I open an intent with textboxes to edit data, but on screen rotation the opened intent closes and leaves only the starting activity. How should I handle it so that my secondary intent is not closed on screen rotation.


Solution

  • Add android:configChanges="orientation|keyboardHidden|screenSize" in your activity declaration in AndroidManifest.xml file

    or handle you data in

     @Override
        protected void onSaveInstanceState(Bundle outState) {
            // store the data in bundle
            super.onSaveInstanceState(outState);
        }
    

    and restore the data in

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        // restore the data from bundle and settext to edittext
        super.onRestoreInstanceState(savedInstanceState);
    }