0

I am new to android. I am making an application. I have created an exit button in every activity for exiting my application, but I do not know how to kill my application when using the exit button.

I know about finish(), but it only destroys the current activity.

I have also used a function, which I created in a utility class, where I check the instance of every activity.

if(activityNAme.getInstance()!=null)

then finish();

But in this approach, I have to write a getInstance() method in every activity.

As I know, the task manager of OS will kill the app if I want it to.

  • What is the best way to kill the process, for example in Core Java, System.exit()?
  • Is there any efficient way to kill the application?
Esoteric Screen Name
  • 6,082
  • 4
  • 29
  • 38
Ashok Singhal
  • 520
  • 1
  • 5
  • 10
  • 7
    "I am giving an exit button in every activity button for exiting my application" -- please don't: http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238#2034238 – CommonsWare Jun 13 '13 at 14:09
  • Take a look http://stackoverflow.com/questions/2092951/how-to-close-android-application – Dmitry Guselnikov Jun 13 '13 at 14:14

2 Answers2

1

call moveTaskToBack(true) on your Activity instead of System.exit(). This will hide your application until the user wants to use it again.

The longer answer starts with another question: why do you want to kill your application?

The Android OS handles memory management and processes and so on so my advice is just let Android worry about this for you. If the user wants to leave your application they can press the Home button and your application will effectively disappear. If the phone needs more memory later the OS will terminate your application then.

Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71
-2

try to finish current on switching to another activity & on click of exit button call System.exit(0);

Vijju
  • 3,458
  • 1
  • 22
  • 20