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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:18:17+00:00 2026-06-13T23:18:17+00:00

In my application, when the phone is held in portrait mode the filename can

  • 0

In my application, when the phone is held in portrait mode the filename can be retrieved.

When I rotate the phone, the same file is being used to get the preferences, but this particular preference comes back blank.

I checked the one function where I write to this preference but it isn’t called when the phone is rotated.

So, what could be the cause of a change in the sharedpreferences by rotating the phone?

Here is the code that I use:

static String retrieveStoredFilename(Context context) {
    SharedPreferences myPrefs = context.getSharedPreferences(PREF_NAME,
            Context.MODE_PRIVATE);
    String s = myPrefs.getString(FILENAME, "");

    return TextUtils.isEmpty(s) ? (String) null : s;
}

Here is some more code in case it helps. This is from the fragment that is actually messed up by the rotation. In onResume filename is set to null after rotating, but from then on it is null, even when I rotate back.

@Override
public void onPause() {
    super.onPause();
    mIV.getBitmap().recycle();
    mIV.setImageResource(R.drawable.ic_action_search);
    if (myBitMap != null)
        myBitMap.recycle();
}

@Override
public void onResume() {
    super.onResume();
    filename = ControllerFragment.retrieveStoredFilename(getActivity());
    getBitmap(filename);
    mIV.invalidate();
    }

And the two constants are:

public static String FILENAME = "filename";
public static String PREF_NAME = "photobrowser";
  • 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-06-13T23:18:18+00:00Added an answer on June 13, 2026 at 11:18 pm

    The only possibility that I see is that the value of FILENAME is not being persisted. It may be worth looking into the lifecycle of an Activity and Saving Activity state on Android.

    Here is an exert from the android documentation about Configuration Changes.

    Unless you specify otherwise, a configuration change (such as a change
    in screen orientation, language, input devices, etc) will cause your
    current activity to be destroyed, going through the normal activity
    lifecycle process of onPause(), onStop(), and onDestroy() as
    appropriate. If the activity had been in the foreground or visible to
    the user, once onDestroy() is called in that instance then a new
    instance of the activity will be created, with whatever
    savedInstanceState the previous instance had generated from
    onSaveInstanceState(Bundle).

    Because of this your onResume() is never called after an orientation change. The activity goes through the entire lifecycle to onDestroy(). After the orientation change onCreate() is called as it is a new instance of your activity.

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

Sidebar

Related Questions

I am making application where phone mode will changes from silent mode to ringer
In my Windows Phone application I need to get hash using SHA-1 Algorithm. How
In my Windows Phone application I get the colour from xml and then bind
I'm developing Windows Phone application.I'm finished.I need application file.How I create application file like
I am new to Windows Phone 7 application development. Can we create different views
In my Windows Phone application I need to accept an untrusted certificate by default
In my Windows Phone Application when I press a button for navigating to Page1
I am creating a windows phone application, which need to store some data in
I am developing a windows phone application. The webclient does not fire as I
I have a windows phone application and I need to add a user control

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.