Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6331299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:02:12+00:00 2026-05-24T18:02:12+00:00

I have a small activity with an EditText and an imageview and a button.

  • 0

I have a small activity with an EditText and an imageview and a button. When you press the button it launches camera for result, and when it returns it changes the imageview to the picture you’ve just taken.

But when the orientation changes, the imageview resets back to the default one on the layout.

What I tried doing was setting a boolean called custom, and when you take a picture it sets it to true. I overrid onConfigurationChanged() and if custom is set to true I restore the image.

My problem now is the EditText becomes erased — How can I restore the EditText after configuration change? My first attempt was storing it’s content into a String onPause() and then restoring it, but it always comes up blank.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:02:12+00:00Added an answer on May 24, 2026 at 6:02 pm

    Usually when UI view does not keep its state, first thing to check is that this UI view has id assigned. Without this id views cannot restore their state.

     <EditText android:id="@+id/text" ... />
    

    If this doesn’t help, you need to save and restore state yourself. Take a look at Handling Runtime Changes. It pretty much explains what you should do:

    To properly handle a restart, it is important that your Activity restores its previous state through the normal Activity lifecycle, in which Android calls onSaveInstanceState() before it destroys your Activity so that you can save data about the application state. You can then restore the state during onCreate() or onRestoreInstanceState(). To test that your application restarts itself with the application state intact, you should invoke configuration changes (such as changing the screen orientation) while performing various tasks in your application.

    You should override onSaveInstanceState() and save your Acitivity state when its called:

    @Override
    protected void onSaveInstanceState(Bundle outState)
    {
        super.onSaveInstanceState(outState);
        outState.putString("textKey", mEditText.getText().toString());
    }
    

    And then restore state in onCreate() or onRestoreInstanceState():

    public void onCreate(Bundle savedInstanceState)
    {
        if(savedInstanceState != null)
        {
            mEditText.setText(savedInstanceState.getString("textKey"));
        }
    }
    

    If this is still not sufficient, you can override onRetainNonConfigurationInstance() and return any custom Object that will be passed to new activity object, when its recreated. More details about how to use it can be found in Handling Runtime Changes. But this function is deprecated in Android 3.0+ (specifically for FragmentActivity where its final). So this cannot be used together with Fragments (which is fine, they have their mechanism to retain objects accross configuration changes).


    And final one – never use android:configChanges. You must have very good reasons to use it, and usually these are performance reasons. It wasn’t meant to be abused the way it is now: just to prevent UI state reset. If this attribute is used, then yes, Activity UI will not be re-set on config change, but Activity state still will be reset when destroyed and re-created later.

    The documentation explains this option pretty well:

    Note: Handling the configuration change yourself can make it much more
    difficult to use alternative resources, because the system does not
    automatically apply them for you. This technique should be considered
    a last resort and is not recommended for most applications

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very small activity that must show an image. If picture is
I have a small problem. In my activity I have an edittext and a
I have small page which has label, DropDownList and a submit button. <div> <asp:label
Just started working with android and ran into a small problem. I am have
I am writing a very small app that just opens the camera app ready
I have a relatively simple layout that contains an EditText . The activity itself
I have been troubled with this small piece of activity to be completed. I
i have an activity where i am opening a camera. i am using framelayout
I have written a small app, that has a Activity to control and display
I am crashing trying to launch a sub-activity. I have a small app to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.