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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:00:06+00:00 2026-05-21T22:00:06+00:00

im going to re-ask this question because there is SO much bad information out

  • 0

im going to re-ask this question because there is SO much bad information out there its really depressing. the short story is that i dont want anything to change or happen when the device orientation changes. 2 of the most popular “solutuions” given to this problem are:

1.You could lock the activity in one orientation by addingandroid:screenOrientation=”portrait” (or “landscape”) to in your manifest.

2.You could tell the system that you meant to handle screen changes for yourself by specifying android:configChanges=”screenOrientation” in the tag. This way the activity will not be recreated, but will receive a callback instead (which you can ignore as it’s not useful for you).

NEITHER of those work. so let me explain my particular problem in more detail…

i am experimenting with a VERY simple app as a learning exercise. i have a text file on a server. the text file has 1 thing in it: a single integer on a single line. this number is the number of image files also stored on this server, and the images are all named 0.jpg, 1.jpg, 2.jpg etc.

ALL of my code is in the onCreate method of my activity (like i said its a simple app).

the app does the following when it runs:

reads the number from the text file.
generate a random number from zero to the number in the file.
loads a random image into an imageview by using the random number in the URL.

when the screen rotates i do not want all of that to happen again. i simply want NOTHING to happen… except that the screen should obviosuly rotate and the image should scale to fit, which it does. but every time the screen rotates all of that code runs and a new random image is selcted. can someone please give me a simple solution with the working code to fix this? i learn by seeing so if you cant provide a code example it wont help.

thanks in advance.

ps… im not looking for a different way of doing what im doing, thats not the point. im looking to FIX the way im currently doing it.

  • 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-21T22:00:06+00:00Added an answer on May 21, 2026 at 10:00 pm

    A very similar question is here: Don't reload application when orientation changes

    Anyway, first of all you should change the code from onCreate to another method and divide it by “create random number and load image from the net” and “set image to view”.

    You have a Bitmap on the activity, that you verify if it’s null everytime the activity starts.

    If it is, do all. If it’s not, just set the ImageView or whatever with the Bitmap you have.

    To avoid destroying the Bitmap when it rotates use:

        Bitmap image = null;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
    
     image = (Bitmap) getLastNonConfigurationInstance();
    
         if(bitmap == null){
             image = downloadImage();
          }
         setImage(bitmap);
    }
    
    
    @Override
    public Object onRetainNonConfigurationInstance() {
        return bitmap;
    }
    

    This works, i’m 100% sure.

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

Sidebar

Related Questions

I am going to try to ask this question without supplying too much source
I am going to ask a question that might sound weird. Is there a
This is going to be a really dumb question, I just know it, but
This is kind of a shot-in-the-dark question, but I'm going to ask it anyway
This is probably a stupid question but I need to ask it because I've
I'm sorry if this is not really an appropriate question to ask on here,
while I wrote this question I figured out a solution but I'm going to
I was going to ask this in tigris.org, however they have maintenance in their
I was going to Ask a Question earlier today when I was presented to
I was going to ask a question here about whether or not my design

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.