I know this question has been asked so many times on SO, so take a moment before you down vote it. I have gone through How to remove application from recent application list?
Quitting an application - is that frowned upon?
Close application and remove from recent apps
And many other questions on SO.
In my application I'm storing the user login details in SharedPreferences. Basically when my application starts - Activity A - Splash screen will show up from 3 seconds. Then it will go to Activity B - The user login page, on press of login the credentials are stored in SharedPreference. Then it will go to Activity C - Home page. I don't want the user to enter the login details each time so I'm storing them in SharedPreference, if the value is present then redirect directly to Activity C - Home Page.
So the flow is like this,
If SharedPreference is empty
A->B->C
If values are present in SharedPreference
A->B->C, I'm checking in Activity B and when the values are present redirect it to C without making the B to come to front.
This all works fine if I open application from launcher. But if I open it from recent list even though the values are present in SharedPreference it is going to Activity B. And when I open it from launcher or recent list the Activity A (splash screen) doesn't show up. Only if I logout and open the application it shows up. What would be the problem?
I tired putting <activity android:excludeFromRecents="true">
so forcing it to not to appear in recent list. Even after this if I open it from launcher it goes to login page i.e Activity B.
I'm overriding the back button like this on Activity C
public void onBackPressed() {
if (backPressedOnce) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
super.onBackPressed();
return;
}
this.backPressedOnce = true;
Toast.makeText(this, "Please press back again to exit.", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
backPressedOnce = false;
}
}, 3000);
}
public void onResume()
{
super.onResume();
this.backPressedOnce = false ;
}
So I have two questions
Q1) How to make splash screen appear each time the user launches it? Q2) If launched from recent list, why it is not redirecting to Activity C even when SharedPreference has values?
Sorry to ask very lengthy question, I know it is not appropriate. Thank you