Atlas91
Atlas91

Reputation: 5904

text from EdittextPreference

My EditTextPreference is this:

<EditTextPreference
    android:title="Name"
    android:summary="namepreferences"
    android:inputType="text"
    android:dialogTitle="name"
    />

in my PreferencesActivity:

namePref = (EditTextPreference)getPreferenceManager().findPreference("namepreferences");

well so far no problem.. now, i have a service with a notification. My goal is pass the namePref value in the Title of the notification.. I wrote this in the service:

SharedPreferences sp = PreferenceManager.getDefaultPreferences(this);
String name;

@Override 
  public void onCreate() {
    name = sp.getText("namepreferences", "NA");

  }

and i insert name in the title of notification but the app crashes sayng that name is null.. I can't solve..

Upvotes: 0

Views: 47

Answers (1)

Simas
Simas

Reputation: 44188

Change to

SharedPreferences sp;
String name;

@Override
public void onCreate() {
    super.onCreate();
    sp = PreferenceManager.getDefaultPreferences(getApplicationContext());
    name = sp.getText("namepreferences", "NA");
}

Upvotes: 1

Related Questions