当我想要访问doInBackground
内的 SharedPreferences 时,我遇到了问题。我怎么能这样做?
非常感谢!
private class postData extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
// I need to access here to my SharedPreferences //
}
}
答案 0 :(得分:2)
解决方案比我想象的要容易。
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", "");
}
}