MR NDOKIST
MR NDOKIST

Reputation: 1

How i can close all activities of my android app in background

I created an android app and i want to start my app at the MainActivity every time my app is launched? That is if my app is at activity B and the user press the home key, then when the app is launched again, it starts at MainActivity instead of activity B? how i can do that ?

Upvotes: 0

Views: 94

Answers (2)

David Wasser
David Wasser

Reputation: 95543

There is a flag for exactly this purpose. In the <activity> declaration for your MainActivity add:

android:clearTaskOnLaunch="true"

This will cause the app to start at MainActivity whenever it is relaunched.

Upvotes: 1

Anuj Sharma
Anuj Sharma

Reputation: 488

There are few ways to do this -

  1. In your activity B override the 'onPause' method and add 'finish()'
  2. In your manifest file where you have added <activity> tag for your activity B, you can add 'android:noHistory=true'. Check this link to understand more - https://developer.android.com/guide/topics/manifest/activity-element

I hope this will solve your issue.

Upvotes: 0

Related Questions