Is there any way to finish Activities automatically in Android Studio?

Serafin William :

first I will give a brief explanation about my program.

I am trying to build a Point Of Sales System in Android Studio, Currently I have 4 Activities which are Login Activities, Register Activities, Forgot Password Activities, and Main Activities.

Basically when you use Finish() in each activities, it will dismiss all operation on the activity, in other words you can't go back to the previous activity after the Intent.

I am wondering instead to put Finish() on each activities, can I do that to all my activities automatically?

Abdul Waheed :

You can do this by keeping no histroy of back stack. Try below code.

Intent i = new Intent("your intent stuff"); 
i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i)

or second way of doing the same You can do this by adding flag in your manifest as well. Add below code in your manifest file.

android:noHistory="true" 

You need to add above tag in application tag.

Hope this will help you.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=102324&siteId=1