Questions tagged [activity-finish]

341 questions
290
votes
11 answers

How to show a dialog to confirm that the user wishes to exit an Android Activity?

I've been trying to show a "Do you want to exit?" type of dialog when the user attempts to exit an Activity. However I can't find the appropriate API hooks. Activity.onUserLeaveHint() initially looked promising, but I can't find a way to stop the…
Peter A
  • 2,919
  • 2
  • 16
  • 4
126
votes
25 answers

How to check if activity is in foreground or in visible background?

I have a splash screen on a timer. My problem is that before I finish() my activity I need to check that the next activity has started because a system dialogue box pops-up and I only want to finish(); once the user has selected an option from the…
Nick
  • 2,593
  • 3
  • 30
  • 59
120
votes
14 answers

How to close the current fragment by using Button like the back button?

I have try to close the current fragment by using Imagebutton. I am in Fragment-A and it will turn to the Fragment-B when I click the button. And when I click the button at Fragment-B , it will turn to the Fragment-C and close the Fragment-B. If I…
Wun
  • 6,211
  • 11
  • 56
  • 101
84
votes
8 answers

How to press back button in android programmatically?

In my app I have a logout functionality. If user clicks logout it goes to home screen. Now I am exiting my app by pressing back button. But what I want is I need to exit automatically(i.e Programmatically) as same like as back button functionality.…
vinothp
  • 9,939
  • 19
  • 61
  • 103
81
votes
9 answers

How to finish current activity in Android

I have an Android application. I am making a loading screen with a progress bar. I entered a delay in the onCreate method. When the timer finishes, I want to finish the current activity and start a new one. It just gives me an exception when it…
Shah
  • 4,990
  • 10
  • 48
  • 70
73
votes
21 answers

Finish all activities at a time

I have an application with multiple pages i.e., multiple activities and some of them remain open. Is there a way to close all activities at once?
steve
  • 1,365
  • 4
  • 19
  • 33
67
votes
6 answers

Close application and remove from recent apps/

I know this question is common and asked many times on Stack Overflow, but after visiting nearly the four pages of search engine results and nearly the 20 question of Stack Overflow regarding this issue, I found that none of them is resolved or…
Hamad
  • 5,096
  • 13
  • 37
  • 65
44
votes
4 answers

Difference between finish() and System.exit(0)

I'm talking about programming in android. In early days I thought that, finish() closes current activity and go back to the previous in Activity stack, and System.exit(0) closes the whole application. But I was wrong. I made a small experiment and…
Nizam
  • 5,698
  • 9
  • 45
  • 57
31
votes
6 answers

Android - Shared element transitions with calling activity finish()

I'm working on making an application more Material and I'm just stuck on how to implement some shared element transitions. I have an activity A that starts another B and then calls finish() in order to remove it from the back stack. In my case I…
28
votes
3 answers

Is it a good idea to call finish() after starting a new Activity in Android?

Like: startActivity(intent); finish(); Without calling finish() explicitly, onDestroy() is not called for the former Activity, and I run out of memory (OutOfMemory Exception). So, is it a good idea to call finish() explicitly to prevent OutOfMemory…
Marton_hun
  • 584
  • 2
  • 7
  • 18
27
votes
2 answers

Android: Will finish() ALWAYS call onDestroy()?

Simple question: can you be sure that finish() will call onDestroy()? I haven't found any confirmation on this.
Xander
  • 5,487
  • 14
  • 49
  • 77
26
votes
3 answers

Angular js - detect when all $http() have finished

Ok i have tons of $http() calls all around the app code, i'm wondering is there any way / best practice to detect when all $http() around the app have finished ( success/error donesn't matter what they return, just need to know if finished )? So…
itsme
  • 48,972
  • 96
  • 224
  • 345
25
votes
12 answers

Exit/Finish an app/activity - android

I've got 4 activities say Act1, Act2, Act3 and Act4. A button in Act1 opens Act2, a button in Act2 opens Act3, a button in Act3 opens Act4. I want two things to be done: I've a button in Act4 which directs the user to Act1, the prob is when the…
kumareloaded
  • 3,882
  • 14
  • 41
  • 58
23
votes
2 answers

How to finish every activity on the stack except the first in Android

I'm porting an iPhone app to Android and I can't seem to find a means to pop each activity on the stack except the root activity. In objective-c I would do something like the below [navController popToRootViewControllerAnimated:YES]; Anyone know if…
Toran Billups
  • 27,111
  • 40
  • 155
  • 268
17
votes
1 answer

Android IllegalStateException while finishing Activity

I got this exception "java.lang.IllegalStateException: Can not be called to deliver a result" And didn't immediately understand why. Below is my answer to why this happened, maybe this helps someone.
Divisible by Zero
  • 2,616
  • 28
  • 31
1
2 3
22 23