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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:05:18+00:00 2026-05-25T11:05:18+00:00

I am new in Android. I want to store my bitmap in sharedPreferences. Can

  • 0

I am new in Android. I want to store my bitmap in sharedPreferences. Can anyone tell me how it will possible? Actually my requirements is, I fetch the image from gallery as well as take picture from camera and I set that Bitmap in my ImageView. These all things work properly. But when I click on back button all ImageView will be empty.

So I want to store that Bitmaps throughout my application.

Can anyone help me? I am very much stuck on this.

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-25T11:05:18+00:00Added an answer on May 25, 2026 at 11:05 am

    Hey friends I got the solution of my problem here I post my code so that others can use this solution..

    1). on button click – open camera for captureing image

    ContentValues values = new ContentValues();  
    values.put(MediaStore.Images.Media.TITLE, fileName);  
    mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);  
    
    Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);  
    startActivityForResult(cameraIntent, CAMERA_REQUEST);
    

    2). on button cllick – open Gallery for select image

    Intent galleryintent = new Intent(Intent.ACTION_GET_CONTENT);
    galleryintent.setType("image/*");
    startActivityForResult(galleryintent, IMAGE_PICK);
    

    3). Static variables

    private static final int CAMERA_REQUEST = 0; 
        private static final int IMAGE_PICK = 1;
    

    4). onActivityResult

        protected void onActivityResult(int requestCode, int resultCode, Intent data) 
            {
                switch(requestCode) 
                { 
                    case CAMERA_REQUEST:
                        if(resultCode == RESULT_OK)
                        {
                            String[] projection = { MediaStore.Images.Media.DATA}; 
                            Cursor cursor = managedQuery(mCapturedImageURI, projection, null, null, null); 
                            int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
                            cursor.moveToFirst(); 
                            String capturedImageFilePath = cursor.getString(column_index_data);
                            Log.d("photos*******"," in camera take int  "+capturedImageFilePath);
    
                            Bitmap photo_camera = BitmapFactory.decodeFile(capturedImageFilePath, options);
    
                            if(data != null)
                            {
        img_1.setImageBitmap(photo_camera);
                                    prefsEditor.putString(Global.PHOTO_1,capturedImageFilePath);
        }
        }
    case IMAGE_PICK:
                    if(resultCode == RESULT_OK)
                    {  
                        Uri selectedImage = data.getData();
                        String[] filePathColumn = {MediaStore.Images.Media.DATA};
    
                        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
                        cursor.moveToFirst();
    
                        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                        String filePath = cursor.getString(columnIndex);
                        cursor.close();
    
    //                  Bitmap photo = BitmapFactory.decodeFile(filePath);
                       Bitmap photo_gallery = BitmapFactory.decodeFile(filePath,options);
                       img_1.setImageBitmap(photo_gallery);
                            prefsEditor.putString(Global.PHOTO_1, filePath);
    }
    
    }
            prefsEditor.commit();
    }
    

    5). in onDestroy()
    You have to destroy all bitmap which you setted.

    @Override
        public void onDestroy()
        {
            super.onDestroy();
            if(photo_camera != null)
            {
                photo_camera.recycle();
            }
            if(photo_gallery != null)
            {
                photo_gallery.recycle();
            }
    }
    

    6). At the time when you fetch data from sharedPrefrences you have to convert string in to Bitmap and then you can set bitmap in ImageView.
    for example, Bitmap bit1 = BitmapFactory.decodeFile(strimg1);
    and then set , imageView.setImageBitmap

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

Sidebar

Related Questions

I am a new developer on Android and I want store user data in
I'm new in Android programming and I want to find how to store data
i am new to android, i want to store the time and retrieve the
Hai! I am new to android. I want to store the images into the
Im new to android and I want to create kind of CRUD with SQLite.
I am new to android and i want to import some classes to my
I am a new android app developer and i want to use google map
I am new in android and i want to do parsing through api and
I am new android app developer i want make app for tablets and phone
We are designing a new application for Android and we want to make it

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.