Reputation: 4292
The Task
I am supposed to connect two application that I made in android . Lets call one of them A (with activities A1 , A2, A3) and B (activities B1 ,B2 , B3) . A user would login from Application A ,and would be redirected to Application B . In Application B , the user might hop between activities . After he is done , he would press LOGOUT from Application B , and would be redirected to Application A . Upon doing this , I want the Application B to be cleared from the backstack .
The Problem
Even though upon logout I am finishing all the activities from the stack , the application name B is still mentioned in the back stack .
What I have achieved so far
This is how I invoke the Application B from Application A
Intent intent= new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("appB", "appB.MainActivity"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(ARG_G2G_ACCESS_TOKEN, mTokenResponse.getAccessToken());
startActivity(intent);
Upon logout , this is how I call the application A again . Firstly I finish all the activities that are running in the Task . Then I do
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setComponent(new ComponentName("appA", "appA.MainActivity"));
However even with the above the Application Application B is still mentioned in the Backstack. I would like that to be removed when B is launched from A.
Thanks
Upvotes: 0
Views: 1439
Reputation: 242
check the answer by Luke at the link below:
Close application and remove from recent apps/
<activity
android:name="com.example.ExitActivity"
android:theme="@android:style/Theme.NoDisplay"
android:autoRemoveFromRecents="true"/>
enter code here
Then create a class ExitActivity.java:
public class ExitActivity extends Activity
{
@Override protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if(android.os.Build.VERSION.SDK_INT >= 21)
{
finishAndRemoveTask();
}
else
{
finish();
}
}
public static void exitApplication(Context context)
{
Intent intent = new Intent(context, ExitActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(intent);
}
}
Upvotes: 2
Reputation: 75788
According to your question, You can add finish ()
or use android:noHistory="true"
finish ()
: Call this when your activity is done and should be closed.
Intent intent= new Intent(Intent.ACTION_MAIN);
.....
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
.........
startActivity(intent);
finish();
You can visit here How to finish current activity in Android .Hope this helps .
Upvotes: 2