mohan
mohan

Reputation: 13165

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

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

Upvotes: 5

Views: 1580

Answers (3)

Android Killer
Android Killer

Reputation: 18499

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.

Upvotes: 8

anshu
anshu

Reputation: 175

finish() android uses to end the activity by calling it in program. (Note, you can also use onDestroy()). FLAG_ACTIVITY_CLEAR_TOP clears all the activities that are top of the current activities inside the Activity stack.

Upvotes: 1

drooooooid
drooooooid

Reputation: 1584

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

Upvotes: 3

Related Questions