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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:41:31+00:00 2026-05-27T06:41:31+00:00

I wrote some test code to learn how to use SharedPreferences. The app saves

  • 0

I wrote some test code to learn how to use SharedPreferences. The app saves data fine, but when I ran the application again by pressing “run” on eclipse, the console window said it was uploading, installing, and starting the application. Since it said installing again, I was expecting the data stored with SharedPreferences to be deleted. However, the old data was still displayed when i went into the activity.

My program runs like this:

  1. splash screen
  2. list menu activity with 3 activity options
  3. the target activity where i implemented the saving function

Here is my code for that specific activity:

public class StartingPoint extends Activity {
/** Called when the activity is first created. */

int counter;
Button add;
Button sub;
TextView display;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    counter=0;

    add= (Button) findViewById(R.id.bAdd);
    sub= (Button) findViewById(R.id.bSub);
    display= (TextView) findViewById(R.id.tvDisplay);

    add.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            counter++;
            display.setText(""+counter);
            display.setTextSize(counter);
        }
    });
    sub.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            counter--;
            display.setText(""+counter);
            display.setTextSize(counter);
        }
    });

}

@Override
protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();

    SharedPreferences prefs = getPreferences(0); 
    int getfromfile = prefs.getInt("counter_store", 1);
    counter=getfromfile;
    display.setText(""+getfromfile);
    display.setTextSize(getfromfile);
}

@Override
protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();

     SharedPreferences.Editor editor = getPreferences(0).edit();
     editor.putInt("counter_store", counter);
     editor.commit();
}
}
  • 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-27T06:41:31+00:00Added an answer on May 27, 2026 at 6:41 am

    Since it said installing again, I was expecting the data stored with SharedPreferences to be deleted

    Re-running the application from Eclipse is akin to doing an upgrade on the app in production. All data associated with the app is left intact.

    You can clear out the old data in the emulator by the same means as you would use on a phone, via the Settings application and its Applications screen.

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

Sidebar

Related Questions

I wrote some test code like this which compiled and worked fine... void threadtest()
I'm trying to instantiate a class from variable, and wrote some test code. But,
I just wrote some code to test the behavior of std::equal, and came away
I just wrote some NIO-code and wonder how to stress-test my implementation regarding SocketChannel.write(ByteBuffer)
I'm running some test to prove a concept and i just wrote this code
I wrote some code to generate a boost::mpl::vector to use as a lookup table
I wrote some code with a lot of recursion, that takes quite a bit
I wrote some CSS in my HTML code to create rollover buttons. Then i
I wrote some code recently (ISO/ANSI C), and was surprised at the poor performance
I wrote some small apps using .NET 3.5 but now I am stuck with

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.