In my Android app i have a Google plus login activity with the method
@Override
public void onConnected(Bundle connectionHint) {
String accountName = mPl
Following @MysticMaggic's answer, i finally got it to work.For future reference, this is what i did:
In the onCreate(Bundle savedInstanceState) method of my UserDetailsCaptureActivity.java class (where i want to save the sharedPreferences) i did
SharedPreferences userDetailsPrefEditor = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
final Editor editor = userDetailsPrefEditor.edit();
final Intent userProfileDisplayIntent = new Intent(this, UserProfileActivity.class);
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId() == R.id.userDetailsCaptureButton) {
new EndpointsTask().execute(getApplicationContext());
editor.putBoolean("hasSetDetails", true);
editor.commit();
startActivity(userProfileDisplayIntent);
}
}
});
and then in the onConnected() method of my LoginActivity (where i want to access the sharedPreferences and check if the user has already entered their details) i did this
@Override
public void onConnected(Bundle connectionHint) {
...
SharedPreferences userDetailsPrefEditor = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
boolean hasSetDetails = userDetailsPrefEditor.getBoolean("hasSetDetails", false);
...
if (hasSetDetails == true) { //If user has already entered their details show profile page, else show user details capture screen.
Intent userProfileDisplayIntent = new Intent(this, UserProfileActivity.class);
startActivity(userProfileDisplayIntent);
} else {
Intent userDetailsCaptureIntent = new Intent(this, UserDetailsCaptureActivity.class);
startActivity(userDetailsCaptureIntent);
}
}
That's all.