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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:34:48+00:00 2026-05-30T15:34:48+00:00

I have made a program code for shared preference in android. But i am

  • 0

I have made a program code for shared preference in android. But i am confused with sharedpreference. I am updating the sharedpreference if its not the same as earlier but every time i get the same value when i retrieve its value. Also please let me knw how to delete sharedpreference on onDestroy().

Bundle bundle = this.getIntent().getExtras();
    resid=bundle.getString("locid");

    SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
    String prefresid = app_preferences.getString("preflocid", null);
     Log.i("pref res id is",""+prefresid);
    if(prefresid!=null)
    {
        if(resid.equalsIgnoreCase(prefresid))
        {
                Log.i("preference res id is the same","");
        }
        else
        {

            SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(getBaseContext()).edit();
            Log.i("preference res id is not same","creating new");
            //SharedPreferences settings = getSharedPreferences("myfile", 0);
           //   SharedPreferences.Editor editor = settings.edit();
             e.putString("preflocid",resid);
             e.commit();
        }
    }
    else
    {
          Log.i("new preference res id created",""+prefresid);
          SharedPreferences.Editor editor = app_preferences.edit();
          editor.putString("preflocid", resid);
          editor.commit();
          Log.i("new preference res id created","");
    }
  • 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-30T15:34:49+00:00Added an answer on May 30, 2026 at 3:34 pm

    Have just one object of default SharedPreference and have editor onto that like:

    SharedPreferences s_pref= PreferenceManager.getDefaultSharedPreferences(context);
    Editor edit=s_pref.edit();
    

    now you will have to use this editor directly wherever it is required.

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

Sidebar

Related Questions

I have made a program with a scroll pane, but it is not working.
I have made a program that continuously monitors a log file. But I don't
i have made a program in vc++ 2010 in win7 but since the submission
I have made a program in C# 2010 and my code contains a Tuple,
I have made a program on eclipse. But how can I get the program
I have made some c code for a program, which does some psycho-acoustics on
I made a program using VB and I lost the source code but I
EDIT: I have changed my program according to suggestions people have made but I
I have made a program in Java that calculates powers of two, but it
I have made a program in c and wanted to see, how much memory

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.