Reputation: 339
I have a problem when I want to access to my SharedPreferences inside doInBackground
. How can I do this?
Really thanks!
private class postData extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
// I need to access here to my SharedPreferences //
}
}
Upvotes: 1
Views: 3495
Reputation: 339
The solution was easier than I thought.
private class postData extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext() );
String userName = sharedPrefs.getString("auth_username", "");
String userPass = sharedPrefs.getString("auth_password", "");
}
}
Upvotes: 2