I am trying to send one string through shared preferences to another activity. I want to call the same activity back.
I have multiple activities which calls one activity in common. So I want to Identify from which the common activity has been called and want to go back to the same activity from which it is called.
This I have done in 1st Activity:
SharedPreferences mPrefs = getSharedPreferences("Type", 0);
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("gosend","1");
editor.commit();
In 2nd activity
SharedPreferences mPrefs = getSharedPreferences("Type1", 0);
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("goride", "2");
editor.commit();
In common activity
useLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences mPrefs = getSharedPreferences("Type", 0);
activityType = mPrefs.getString("gosend", "1");
SharedPreferences mPrefs1 = getSharedPreferences("Type1",0);
goride = mPrefs1.getString("goride","2");
if(activityType.equals("1")) {
intent = new Intent(ChooseFromMapActivity.this, GoSend.class);
startActivity(intent);
}
if(goride.equals("2"))
{
intent = new Intent(ChooseFromMapActivity.this, GoRideActivity.class);
startActivity(intent);
}
}
});
}
Now when I am calling common activity from 1st activity , I am not returning back to the same rather 2nd activity is getting called.
whats going wrong??
Edit
I tried this : Still dose not work
useLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences mPrefs = getSharedPreferences("Type", 0);
activityType = mPrefs.getString("gosend", "0");
// SharedPreferences mPrefs1 = getSharedPreferences("Type1",0);
// goride = mPrefs1.getString("goride","0");
switch (activityType){
case "0":
intent = new Intent(ChooseFromMapActivity.this, GoSend.class);
startActivity(intent);
break;
case "1":
intent = new Intent(ChooseFromMapActivity.this, GoRideActivity.class);
startActivity(intent);
break;
}
}