Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Intent.FLAG_ACTIVITY_CLEAR_TOP and finish in android

Tags:

android

What is the difference between Intent.FLAG_ACTIVITY_CLEAR_TOP and finish() in Android?

like image 814
mohan Avatar asked Dec 21 '22 06:12

mohan


2 Answers

The differerence between these two are as follows:

1.finish() you can use to end the activity in which you are right now present and also it will end one activity at one time.

2.In case of FLAG_ACTIVITY_CLEAR_TOP,It will end all the activities those are on top of the current activities inside the stack.There may be more than one activity.

like image 97
Android Killer Avatar answered Dec 28 '22 11:12

Android Killer


suppose you are starting activities one after another in the order A-->B-->C-->D,ie activity B started from activity A,activity C started from activity B and so on. Now calling startactivity(A) from activity D with intent flag FLAG_ACTIVITY_CLEAR_TOP finishes all activities in between (here B and C) and starts A.

calling Finish() from your activity closes current activity

like image 20
drooooooid Avatar answered Dec 28 '22 09:12

drooooooid