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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:05:03+00:00 2026-06-14T18:05:03+00:00

My app uses PreferenceManager.getDefaultSharedPreferences(getBaseContext()) and then sets a couple of preference values. While running

  • 0

My app uses PreferenceManager.getDefaultSharedPreferences(getBaseContext())

and then sets a couple of preference values. While running tests I want to clear these values and start off from a known state. Is there any way default shared preferences can be set up or initialized in the setUp function?

  • 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-14T18:05:04+00:00Added an answer on June 14, 2026 at 6:05 pm

    The code you need is as following:

    Context context = instrumentation.getTargetContext();
    PreferenceManager.getDefaultSharedPreferences(context).edit().clear().commit();
    

    If your application uses any different shared preferences you may need to clear them too in the following way:

    context.getSharedPreferences("XXX", Context.MODE_PRIVATE).edit().clear().commit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app uses the typical pattern of starting a CLLocationManager and then calling stopUpdatingLocation
My app uses Barcode Scanner. I want to launch the scanner when I open
Our app uses a string to house character-values used to indicate enum values. for
My app uses the UIImagePickerController to record a video, and I'm then uploading it
My app uses navigator.geolocation provided by PhoneGap. When running the app on iPhone is
My app uses GPS. At first launch, user is asked if he want's to
My app uses the android.support.v4.view.ViewPager class. For each page in the ViewPager, I want
My app uses monetary values, and I would like to represent these values in
My app uses a local SQLite database to read data. Just a couple of
My app uses a database, it comes pre-populated with about 50 values. I'm accomplishing

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.