I have the MainActivity
which is welcome activity and some other ones.
Lets suppose Act1
, Act2
and Act3
.
I want the program automatically redirect from MainActivity
directly to last visited activity on every app launch.
whether Act1
, Act2
or Act3
Well, I tried to do this jump from main activity to last visited activity, but it didn't work.
here's code what I've already tried and didn't work:
MainActivity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadLocale();
setContentView(R.layout.activity_main);
SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
int restoredLevel = prefs.getInt("level", 0);
if (restoredLevel > 0) {
Intent i = new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
}
}
Act1:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Act1);
SharedPreferences.Editor editor = getPreferences(Context.MODE_PRIVATE).edit();
editor.putInt("level", 1);
editor.apply();
}
(I simply want to change launcher activity depending on last visited activity, if you know any better solution for my problem, I will be thankful)