Questions tagged [activity-finish]
341 questions
17
votes
2 answers
alternative to finish() method for Service class? To kill it dead
I have used the method finish() before in several activities without problems.
however when I tried to call it inside of the broadcast receiver I get the error message from the compiler that "the method finish() is undefined for the type…

Kevik
- 9,181
- 19
- 92
- 148
16
votes
2 answers
Android: How to know if an activity is finished?
I'm working on an app that plays mp3 files automatically and in succession from within a given activity. it knows when the current mp3 play is completed by listening for an "onCompletion" event from the MediaPlayer.
However, if I return to the…

Jack BeNimble
- 35,733
- 41
- 130
- 213
14
votes
2 answers
Finishactivity doesn't finish the activity?
I'm trying to get my activity to close and return with the result, I do have onActivityResult in my parent activity, and I have used close to the same method below in other places where it works.
public void deleteFile(){
boolean…

Anders Metnik
- 6,096
- 7
- 40
- 79
14
votes
2 answers
Why is a call to finish() causing onCreate() to be called, starting a new Activity?
(Yes, I've already looked at existing questions related to this problem.)
I am calling finish() from my Activity's Up button listener. But although onDestroy() does get around to being called, first onPause() is called and then, surprisingly,…

Alyoshak
- 2,696
- 10
- 43
- 70
14
votes
2 answers
Finish activity in dialog class
In my MainActivity I call
MyDialog dialog = new MyDialog(MainActivity.this);
dialog.show();
MyDialog is my own class where I customize the dialog.
In the dialog is a button. I want that the MainActivity and the dialog finishes/dissappears when…

L3n95
- 1,505
- 3
- 25
- 49
14
votes
3 answers
Android closing child activity from parent activity
I wanted to close child activity from parent activity. My flow is like: activity A is opened, inside Activity A I am opening activity B. But at same time my activity A is doing some background task. When I got result of my background task I wanted…

nilkash
- 7,408
- 32
- 99
- 176
12
votes
3 answers
Android : startActivityForResult() with BACK button functionality
I would like to start a new activity for a result, with startActvityForResult(), but I would like to have the back button working as normal in the new activity.
Currently when I invoke a new Activity for result, nothing happens when I press the…

Arnab Chakraborty
- 7,442
- 9
- 46
- 69
9
votes
5 answers
How to finish() an Activity when Home button pressed
For a complicated reason I need to be able to finish() my activities when the user presses the HOME button.
The story here is that I have a homescreen widget that launches a different part of my application that has a completely transparent activity…

Yossi
- 1,226
- 1
- 16
- 31
9
votes
3 answers
What method is being called when I close an app
I read all about the activity lifecycle and it's methods.
I still couldt find an answer:
When I close my app, from the "open apps" menu (in galaxy4 it's a long press on the home button, in nexus5 it's the right button ...) what method is being…

nivklein
- 91
- 1
- 1
- 3
8
votes
2 answers
finish() finish the activity but it is still on background
I have a question concerning the finish() method of an activity in android studio:
I have this simple code:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
…

Bazouk55555
- 557
- 6
- 24
8
votes
2 answers
Using finishAndRemoveTask() method of Activity class on API levels lower than 21
I need to delete app from recently used apps list. There is no problem on API level 21 and above. I use finishAndRemoveTask() method. But that method cannot be used on API levels lover than 21. How can I call that method on API levels lover than…

cimenmus
- 1,386
- 4
- 18
- 31
7
votes
3 answers
Should I always finish one activity before going to another?
Do you always call finish() on some activity before going to another activity?
For example, in order to prevent user going to the previous activity via mobile back button, some people suggest that you should finish all activities, except the main…

sandalone
- 41,141
- 63
- 222
- 338
7
votes
2 answers
Android - How to end a Fragment
In my application I have a navigation drawer, and the way my app works is there is only one activity and if you select something from the Navigation drawer it starts/replaces the current fragment. How Can I make it so that when something is selected…

user222786
- 547
- 4
- 7
- 17
7
votes
3 answers
finish activity in onActivityResult does not work
I have a pair of activities that must live or die together. Basically AlphaActivity does some work and then dispatches an intent (startActivityForResult()) for BetaActivity. When BetaActivity is done, I want it to dispatch an intent…

learner
- 11,490
- 26
- 97
- 169
7
votes
2 answers
Calling finish() doesn't finish the activity
I want to finish my activity when it pauses for specific reasons. Up till recently my code was working perfectly but recently the finish() method stopped doing its job for some reason. Also, when the finish() method is called, I get the following…

Tanuj Nayak
- 607
- 1
- 8
- 22