boo-urns
boo-urns

Reputation: 10376

How to close an Activity, not the whole app

I'd like to destroy an Activity when the user clicks on a button (not the back button, a different button). I've decided to just call super.onBackPressed. Is that okay? What's a better way to close the current Activity without closing the whole app?

Upvotes: 1

Views: 481

Answers (3)

Arash GM
Arash GM

Reputation: 10395

for closing an Activity you can use finish() , but you have to aware of back stack, if you finish your last activity in the stack so there will be no activity in your stack and you must restart your app .

see more information on : Task and BackStack

Upvotes: 3

Anukool
Anukool

Reputation: 5391

The default implementation of super.onBackPressed finishes the activity.
Instead of using super.onBackPressed , Better way to close the current activity will be to call finish() method.

Upvotes: 0

Govil
Govil

Reputation: 2054

Also, When you press the back button, the onResume method is called. Use onResume Method and refresh your stuff there.

Also, if it is listView refresh the data -> https://stackoverflow.com/a/12662994/2006412

Upvotes: -1

Related Questions