1

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?

user5243421
  • 9,066
  • 22
  • 65
  • 102
  • 1
    Just call finish(). http://developer.android.com/reference/android/app/Activity.html#finish() – Dhruv Gairola Jan 26 '13 at 05:39
  • finish() method closes your current activity. – Avinazz Jan 26 '13 at 05:40
  • I'm not sure I understand why my question was downvoted. If the answer is so obvious, I guess I'm not good at searching for my question because all of the solutions I found were for closing an Activity and the entire app. – user5243421 Jan 26 '13 at 05:47
  • Possible duplicate of [Android Closing Activity Programmatically](https://stackoverflow.com/questions/5134231/android-closing-activity-programmatically) – Martin Zeitler Aug 03 '18 at 23:41
  • just perform the finish(); function within that activity. I suggest you check out http://youtu.be/P4PqZKmQjjs this video Learn Android Tutorial 1.8 on a splash activity. It helped me understand how it worked better. – MingoVanBurne Jan 26 '13 at 06:00

3 Answers3

3

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

Arash GM
  • 9,996
  • 6
  • 54
  • 73
0

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.

Anukool
  • 4,741
  • 8
  • 25
  • 41
-1

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

Community
  • 1
  • 1
Govil
  • 1,976
  • 18
  • 20