There are actually two ways to solve your problem:
Or set android:launchMode="singleInstance" ( link ) to the manifest of your activity, which is called from a deep link. Thus, an activity is always the only and only member of its task. This way, the action will not reuse any tasks from the back of your application that is already running. Also, be careful with singleInstance if you open the SingleInstance operation with a deep link, and then move from there to another action, and you click back, you get into the parent activity of the current activity, and not your singleInstance activity. Thus, it somehow destroys the standard reverse navigation, and you have to handle all these special cases, which can be quite annoying.
Or, for API> = 16, you can use: finishAffinity() ( reference ) in your onBackPressed() method your activity, but here you must somehow distinguish if the application was opened through a deep link, otherwise it will close your application, even if you just want to return to the main menu.
mathew11
source share