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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:40:48+00:00 2026-06-04T22:40:48+00:00

I am developing an Android Application, where I have an imageView on a page

  • 0

I am developing an Android Application, where I have an imageView on a page and onLongClick it changes from Image A to Image B. However, when they leave the page the imageView goes back to Image A. How can I save the state (im guessing its done onpause, stop and destroy) so that it saves the current image src of the ImageView and load it up next time the page is accessed and created. I have never done data saving in Android..

Any simple data saving tutorial/example would be greatly appreciated.

  • 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-04T22:40:50+00:00Added an answer on June 4, 2026 at 10:40 pm

    Something along these lines should help you out:

    // Use a static tag so you're never debugging typos
    private static final String IMAGE_RESOURCE = "image-resource";
    private int image;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // if there's no bundle, this is the first time; use default resource
        if (savedInstanceState == null) {
            image = R.drawable.default;
        } else {
            // if there is a bundle, use the saved image resource (if one is there)
            image = savedInstanceState.getInt(IMAGE_RESOURCE, R.drawable.default);
        }
    }
    
    @Override
    public void onSaveInstanceState(Bundle outState) {
        // Make sure you save the current image resource 
        outState.putInt(IMAGE_RESOURCE, image);
        super.onSaveInstanceState(outState);
    }
    

    Make sure you set the image variable to the proper resource at the same time you change it in your click listener.

    If you’re looking to remember the state longer than this, look into SharedPreferences.

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

Sidebar

Related Questions

I am developing an android application in which I have to upload image from
I am developing android application in which i have to open option menu from
I am developing an android application where i have to save image in database,Can
I am developing an android application in which I have passed a string from
I have been developing Android application for Android 3.x and now I want to
i am developing an arabic android application and i have the compatibility package referenced
I am currently developing an android application using eclipse and I already have a
I am developing one application in android. In this I have to login into
We've been developing an Android application which includes Google Adsense. However there seems to
I am developing an android application that receives data about events from a server.

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.