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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:43:46+00:00 2026-05-23T17:43:46+00:00

I have created an activity where i have used shared preferences for storing data..now

  • 0

I have created an activity where i have used shared preferences for storing data..now in another activity i have an reset button..when i click on the reset button the data store will be lost..so how that can be done..my code is

code in activity1:

    public void writeToRegister()
    {

            // Write history data to register
            SharedPreferences preferences1  = getPreferences(MODE_PRIVATE);
            SharedPreferences.Editor editor1  = preferences1.edit();
            editor1.putInt("iHistcount", CycleManager.getSingletonObject().iHistCount);
            for(int i=0;i< CycleManager.getSingletonObject().iHistCount;i++)
            {
                editor1.putLong("dtHistoryDate"+Integer.toString(i), CycleManager.getSingletonObject().dtHistory[i].getTime());

            }
            editor1.commit();
    }

    public void readFromRegister()
    {
            // Read history data from register
            SharedPreferences preferences1 = getPreferences(MODE_PRIVATE);
            CycleManager.getSingletonObject().iHistCount=preferences1.getInt("iHistcount", 0);
            for(int i=0;i< CycleManager.getSingletonObject().iHistCount;i++)
            {
                Long x=preferences1.getLong("dtHistoryDate"+Integer.toString(i), 0L);
                CycleManager.getSingletonObject().dtHistory[i]=new Date(x);
            }
    }

code for Activity 2:

Button pBtnReset = new Button(this); 
    pBtnNextMonth.setOnClickListener(pBtnReset OnClickListener);
    Button.OnClickListener pBtnReset OnClickListenernew Button.OnClickListener()
    {
                public void onClick(View arg0)
                {


                }
    };

so what i have to write in second activity reset button so that it clear the stored data

  • 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-23T17:43:47+00:00Added an answer on May 23, 2026 at 5:43 pm

    Get your Editor and call clear() something like this:
    Edit: as the user DDoSAttack mentioned.
    There are two ways of getting SharedPreferences

    1: getting default SharedPreferences

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(con);
    

    2: getting specific SharedPreferences

    SharedPreferences prefs = Context.getSharedPreferences("FileName", Context.MODE_PRIVATE);
    

    and here is how you’ll clear it.

    public void clear()
    {
         SharedPreferences prefs; // here you get your prefrences by either of two methods
         Editor editor = prefs.edit();
         editor.clear();
         editor.commit();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually i have created an singleton class. Now my singleton class extends Activity, and
I have a database with one row of data that will be used across
I have created an activity which sends a number of notifications to status bar.
i have created a workflow activity that do give the item creater of a
I have created a custom workflow activity that copies attachments from a case to
I want to have a class Utils, that will have several methods used all
I have a list activity .I have created a array string []name = new
hi i have created a question answer based app, the question's used to be
I have created a custom Button as follows. file : buttoncontrol.xml <?xml version=1.0 encoding=utf-8?>
I have a couple of tables which are used to log user activity for

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.