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

  • Home
  • SEARCH
  • 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 8976437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:08:03+00:00 2026-06-15T19:08:03+00:00

So instead of creating a database, I’m storing the data using SharedPreference . My

  • 0

So instead of creating a database, I’m storing the data using SharedPreference.

My code is below:

   SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
        editor.putInt("favid"+id, 1);
        editor.commit();
        Toast.makeText(getApplicationContext(), "Select as favorite", Toast.LENGTH_SHORT).show();

Now I want to retrieve that data so I have used below code in other activity:

   strFav = new ArrayList<Integer>();

    if(strFav.size()>0)
        strFav.clear();
    SharedPreferences prefs = getPreferences(MODE_PRIVATE); 
    for (int i = 1; i < 19; i++) {
        int favid = prefs.getInt("favid"+i, -1);
        if (favid != -1) 
        {
          strFav.add(i);
        }
    }

At time of data retrieve, I’m getting all value is -1.

Can any body help me why this is happening? I have committed many entries as 1, but I’m still getting -1 result for all of them.

  • 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-15T19:08:05+00:00Added an answer on June 15, 2026 at 7:08 pm

    See docs about getPrefernces method:

    Retrieve a SharedPreferences object for accessing preferences that are private to this activity.

    So, if you want to share preferences between activities you should use getSharedPreferences with specified name.

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

Sidebar

Related Questions

Using EF 4.1 Code first I wanted to stop EF creating database from Models.
Why is this creating a new row at the bottom with this data instead
Just tried creating a data connection to a SQL 2000 database in VS2010's Server
where can i learn more abt creating database markup in yaml and data fixtures.
I've got the code below to pull hex values from a database and create
when creating a fairly complicated form that will be used to edit a database
I am using Spring JdbcTemplate with the DAO pattern to access a database. Instead
I'm creating a database to track our participants in Access 2010. Main data is
this might be a simple question but when creating a database can you instead
I'm using podscms for creating a database site. I would like to create two

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.