Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity remains on screen Android

Tags:

android

I have a service that is listening to some events. When that event happens, it shows a screen by startActivity(intent)

When the user finishes doing something on that screen, the code calls finish() but instead of 'closing' the complete application, it shows the main/launcher activity.

I mean, whats the best way to remove all app screens from current view? or any way to go around this?

like image 723
shaimagz Avatar asked Aug 22 '26 22:08

shaimagz


2 Answers

The finish() method only finishes the Activity it's called from.

If you want the first Activity to be gone from the stack, you'll have to call finish on it right after you call startActivity(intent). This will remove the initial Activity from the stack, so the newly called Activity is the only one there and closing it will leave nothing behind.

like image 97
kiswa Avatar answered Aug 25 '26 12:08

kiswa


The main activity has probably not finished and is therefore still in the stack of activities. I'm not sure about the right solution, but maybe this helps

http://developer.android.com/guide/topics/fundamentals.html#clearstack

like image 35
Andreas Avatar answered Aug 25 '26 11:08

Andreas