I dont really need the code for this, just the structure of doing it.
I am working on an application where i have a BaseAtivity (extends Activity) with a number of methods and an inner class User. All other activities in my application extends BaseAtivity.
The User class has methods that read and write data using SharedPreferences. So LoginActivity extends BaseActivity, and upon correct login it calls User.login(args) in order to create a shared variable (in MODE_PRIVATE) with user id, user email, and a json with user preferences.
I need to create a Content Provider that will use query() to retrieve data from the logged in User. the content Provider will get data from sharedpreferences and provide them to the appalication calling the Content Provider.
Since my content Provider extends ContentProvider I am not able to extend BaseActivity (that could be a solution). When calling within ContentProvider's method onCreate()
User user = new BaseActivity.User();
I get the error .... "'com.example.myapp.BaseActivity' is not an enclosing class".
Is there a way to call the inner class User from my ContentProvider?
Ok, I solved the problem like this. I didnt find a way to use the User inner class but access the SharedPreferences.
public class UserProfileProvider extends ContentProvider implements SharedPreferences {
@Override
public boolean onCreate() {
SharedPreferences settings = getContext().getSharedPreferences(getContext().getResources().getString(R.string.PREFS_NAME), getContext().MODE_PRIVATE);
Log.d("akis", ":::userProfileProvider:::" + settings.getString(getContext().getResources().getString(R.string.USER_PREFERENCES), "default"));
return false;
}
Of course you have to add all methods that must be overridden by implementing SharedPreferences