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 6687173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:15:26+00:00 2026-05-26T05:15:26+00:00

How do I retain the state of an activity in android? I have two

  • 0

How do I retain the state of an activity in android? I have two layouts for portrait and landscape in layout and layout-land. I am loading the value from service at the time I am showing progress dialog. If loaded user rotates the device to landscape at the time also loading. How do I avoid that? user typed content in webview that also refreshed. How do I avoid that, can anybody provide an example?

Thanks

  • 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-26T05:15:27+00:00Added an answer on May 26, 2026 at 5:15 am

    You can use the onRetainNonConfigurationChange() callback to store arbitrary data. It is called just before your application is about to be recreated.

    Then, in onCreate() just check if some data were put aside by calling getLastNonConfigurationInstance() that returns the Object you put aside or null.

    See this article on android developers.

    Here’s a sample borrowed from the link above:

    @Override
    public Object onRetainNonConfigurationInstance() {
        //this is called by the framework when needed
        //Just return what you want to save here.
    
        return MyBigObjectThatContainsEverythingIWantToSave;
    }
    

    Automagic restore of previously saved state:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        final MyDataObject MyBigObjectThatContainsEverythingIWantToSave = (MyDataObject) getLastNonConfigurationInstance();
        if (MyBigObjectThatContainsEverythingIWantToSave == null) {
            //No saved state
            MyBigObjectThatContainsEverythingIWantToSave = loadMyData();
        } else {
            //State was restored, no need to download again.
        }
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Serialized varibale does not seem to retain its state from classes that were extended.
Its possible to retain a Fragment between Activities? Lets say I have Activity A
Can anybody tell me how to retain the state of inflated layout while configuration
I'm reading this article on how to : correctly retain variable state in Android
I have the following in an XML Document: <ul class=toggle-control toggle-retain-state> I'm using XML::LibXML
I have an Activity with some EditText fields and some buttons as a convenience
I'm using the Telerik RadComboBox control. I have two related combos and when the
I'm a newbie in Android development. Let me explain my problem. I've have a
This sqlfiddle link seems to retain state across invocations: http://sqlfiddle.com/#!2/125bc/1 It contains this schema
I have a webview which is loading a url. If I change the orientation

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.