问题
Lets suppose I am at 4th activity of my app and I have ten activities. I close the activity from 4th level now when i reopen my activity again i have a button on main activity when i click on it I must have to go on 4th activity where i left last time. Now what I do is that I saved every activity number or ID in Shared preference like that
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level1);
SharedPreferences.Editor editor = getPreferences(Context.MODE_PRIVATE).edit();
editor.putInt("level", 4);
editor.apply();
Then i retrieve it in main activity like this:
btnconti.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
int restoredLevel = prefs.getInt("level", 0);
if (restoredLevel >0) {
}
}
});
Now can any body tell me how i can jump to my last visited activity?
回答1:
If you have seperate Activities for all 10 activities u can call an intent as follows inside multiple if conditions of restoredlevel
Intent i = new Intent(getApplicationContext(),ActivtyOfyourlevel.class)
startActivity(i);
来源:https://stackoverflow.com/questions/30162939/jump-from-main-activity-to-last-visited-activity