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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:56:31+00:00 2026-06-05T11:56:31+00:00

I have a PreferenceActivity that I’d like to use with AndroidAnnotations @SharedPref, so the

  • 0

I have a PreferenceActivity that I’d like to use with AndroidAnnotations @SharedPref, so the PreferenceActivity would use the data in the @SharedPref.

Is there a good way to do this? How do I tell the activity to to use @SharedPref I created elsewhere? Is there a good way to do this without setting the value of each preference?

Here is the activity code I’m currently using:

public class SettingsActivity extends PreferenceActivity {

    @SuppressWarnings("deprecation")
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
    }  
}
  • 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-05T11:56:38+00:00Added an answer on June 5, 2026 at 11:56 am

    A PreferenceActivity is an Activity, so you just need to annotate it with @EActivity to start using the annotations, such as @SharedPref.

    If you want to share preferences between activities, AndroidAnnotations has the notion of scope, as defined here.

    You should use the Scope.UNIQUE scope to share it between all activities.

    SharedPref were thought as a way to easily store data into SharedPreferences. Not necessarily to be used with PreferenceActivity.

    You can use getSharedPreferences() to access the shared preferences instance, you can’t use that to define the preference to use in the activity. So it’s mainly a matter of using the right Android APIs.

    @EActivity
    public class SettingsActivity extends PreferenceActivity {
    
        @Pref
        MyPrefs_ myPrefs;
    
        @Override
        public void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            getPreferenceManager().setSharedPreferencesName("MyPrefs");
            addPreferencesFromResource(R.xml.preferences);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PreferenceActivity that gets its data from a web service(Call forward Numbers,
I have an application that uses the new features of honeycomb for the PreferenceActivity.
I have this widget in android, that displays an image and gets updated periodically
I have a PreferenceActivity that loads two Fragments via the xml file for the
I have the following ListPreference in a PreferenceActivity that I wish to populate with
I have a class that extends PreferenceActivity and shows the preference screen of my
I would like to be able launch a 2nd Preference screen from my PreferenceActivity.
I have a menu that comes up for my PreferenceActivity. In my child preference
I'm using PreferenceActivity to set some preferences about another BroadcastReciever that i have. While
So I have found that android PreferenceScreen is not very style-friendly. Is there a

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.