This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Android and the fly likes How to stop all activities and exit from android application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "How to stop all activities and exit from android application " Watch "How to stop all activities and exit from android application " New topic
Author

How to stop all activities and exit from android application

Satchidananda Mohanty
Ranch Hand

Joined: Mar 12, 2008
Posts: 77

Hi there !!

I wanted to stop all the activities and exit from my current android application. Can you suggest any better way to handle this.


Thanks in advance.


Zeet

SCJP 6.0
Mohan Prasath
Ranch Hand

Joined: Jul 25, 2011
Posts: 38

While invoking your child activity you have to set the following flag to your intent. FLAG_ACTIVITY_CLEAR_TOP - this tag gives importance to the
intent to be started and removes all other activities in the stack.

Note : Also set FLAG_ACTIVITY_SINGLE_TOP in the list of flags.


With regards,
Mohan Prasath
Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 124

is System.exit(0) not a good option for this?
Mohan Prasath
Ranch Hand

Joined: Jul 25, 2011
Posts: 38

There are many reasons why GC usage is not promoted.
1. The use of System.gc() is often considered to be inefficient code. Technically System.gc() works when there is anything to be garbaged. (This is my personal opinion and a general knowledge from my work experience)
2. You can't actually say what it does with the memory when you call it. And technically Java Heap space does not depend upon Java Memory Allocations.
3. As mentioned Google IO 2011, GC usage has to be avoided. Memory Management in Android
Satchidananda Mohanty
Ranch Hand

Joined: Mar 12, 2008
Posts: 77

Thank you Mr. Mohan,
Let me try this.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
You can call finish() from with the main Activity to exit.

I doubt that calling System.gc() is even allowed, but it would indeed be a bad choice, as the app doesn't get a chance to clean up properly.
Satchidananda Mohanty
Ranch Hand

Joined: Mar 12, 2008
Posts: 77

Finish() only finishes that current Activity and moves back to the previous Activity.
 
Consider Paul's rocket mass heater.
 
subject: How to stop all activities and exit from android application
 
Similar Threads
Does android have any wizard style frameworks?
How to Exit an Application
Not much Android in the book. Ok, so where so we go.
is this propel way shutdown app
I am a SE and EE developer plan to learn Android for ME