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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:52:49+00:00 2026-05-18T10:52:49+00:00

When starting a certain activity of my app, the user is welcomed with a

  • 0

When starting a certain activity of my app, the user is “welcomed” with a dialog that he must fill with some data in order to proceed. Then, in the activity per se, the user has 2 buttons that enable him to dynamically create and delete an infinite number of fields (that are composed by several views)

As you know, when the screen orientation changes, the activity is restarted so every information is lost. Obviously, this can be problematic.

In order to handle the screen orientation, android documentation advises developers to use onRetainNonConfigurationInstance(). The only problem is that if you use it to save objects in a context all the views tied will leak. This is further problematic in my case, since the data in that activity is inherently tied to its view, which, in turn, is tied with its context.

Android Documentation does not recommend developers to handle configuration changes themselves. They state (and I quote) “in general, a short-term solution that will only complicate their lives later”

I can bypass the initial dialog easily, creating a hasBeenShown Boolean and set it to true, for instance. I can even bypass the “dynamically created views” problem by saving their metadata: in this case the number of fields generated, their type, their relative position to each other, their text or selection, and so on… (with some minor bugs, but nothing serious).

But since fields(views) are generated dynamically with layoutInflate(and thus we can have an infinite number of views), when re-generating those same fields after screen orientation change, the application gets really really slow even on emulator. With 20 fields (approximately 120 views) on a real device (Samsung Galaxy S) it took almost 1 minute to complete.

Strangely, when I passed views directly (and thus, leaking all that stuff), it took my Samsumg Galaxy S less than 10 seconds to complete.

With this information, what do you think its the best approach?

(1) – Let the fields reset? (not really an option, I bet anyone would get pissed if they inadvertently tilt their screen =P)

(2) – Add a loading screen while android takes care of changing screen orientation?

(3) – Block screen orientation change

(4) – Handle screen orientation change myself, and hope the impeding Doom Android docs talk about never comes.

P.S: A bit offtopic, but when my activity finishes, all memory is released right?

  • 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-18T10:52:49+00:00Added an answer on May 18, 2026 at 10:52 am

    Your situation is different from mine, but a similar solution may be in order.

    Again, because Android will destroy and recreate on an orientation change I initially had issues with Async tasks doing network communication. Obviously I shouldn’t be creating new requests on every orientation change when the first one is still executing.

    To save some network usage and headaches I just ‘handle’ the orientation change myself. By placing this code in your AndroidManifest.xml

    <activity android:name=".whatever" android:configChanges="keyboardHidden|orientation"/>
    

    you allow Android to keep the current context, with views and variables etc. What happens is the layouts will resize themselves but if you designed correctly then you should be ok.

    AFAIK the only thing I am preventing Android from doing is using specialized layouts based on the orientation of the device (which I don’t need) and so far I have not been hit by the forewarned impending doom.

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

Sidebar

Related Questions

I have an arraylist in Java that I fill with certain data, but I
I've received report from the user of an app I've written that he gets
I'm working on an App that needs to have a custom ringtone for certain
I need some help starting a function that will parse through an array, check
I need to find a certain amount of prime numbers in ascending order, starting
I am starting an app from the debugger. How can I connect a certain
Starting with an empty dataframe, I need to fill the dataframe as follows: A
In my onCreate method in main activity i have some code which is checking
I am working on some code that deals with date ranges. I have pricing
I have to develop an application that gives a popup message at a certain

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.