Reputation: 119
I've got an application that launches an introduction flow on first run like this:
ON FIRST RUN
A: Intro text
B: Terms and conditions
C: Choose language
After all these steps have been completed, the application sets a first_run attribute to false and launches activity D.
Now, what I want to do is either clear the activity stack so that when the user presses the back button it goes back to the Home screen rather than activity C and then when the application launches again it goes straight to activity D.
Any ideas on how I would go about doing this?
EDIT
I'm aware that calling finish() on each activity removes it from the stack. But my real problem is that if the user wants to go back from B to A it won't work if I've already called finish() on A. Sorry for not specifying this earlier.
Upvotes: 0
Views: 182
Reputation: 1934
This is gonna work for sure, apologies for the last post. I realised it later that it wont work.
In Activity A, B and C use:
BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("ActivityA", "finishing A");
finish();
}
};
@Override
protected void onDestroy() {
unregisterReceiver(myReceiver);
super.onDestroy();
} // This is mandatory to unregister the receiver, else error occur
In onCreate of these activities, add:
IntentFilter myFilter = new IntentFilter("finish_my_activities");
registerReceiver(myReceiver, myFilter);
In activity D, where you wanna finish all this:
sendBroadcast(new Intent("finish_my_activities"));
//Where ever you wanna finish those activities
Upvotes: 6
Reputation: 11776
well use SharedPreferences to save your first_reun attribute and check its value on the OnCreate of activities (A, B and c).
And then in your manifest add (android:noHistory="true") to the (D) Activity.
Upvotes: 0