tags:

views:

63

answers:

3

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?

+1  A: 

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

Andreas
+3  A: 

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.

kiswa
The answer is wrong Because the service calls startactivity, so we cant call Finish afterthat, because it starts from the service and not from the firstactivity.It looks like because its the default one, its part of the same groupor somehting.
shaimagz
So, the problem is that the Service is opening more than one Activity when it activates your app? Is the Activity you're calling directly accessible via the Manifest? It could also be that the app was already 'live' and brought to the front by calling a child Activity.
kiswa
+1  A: 

This is kind of overkill... but I use this for my quit() functions

int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
System.exit(0);
finish();
androidworkz