tags:

views:

261

answers:

7

pl;ease suggest me how can i close my whole Android Application with one line code

+3  A: 

You could finish your Activity by calling Activity.finish(). However take care of the Android Activity life-cycle.

Roflcoptr
i want whole activities are finished by single call
Amit
this is a single call.
Roflcoptr
+1  A: 

If you close the main Activity using Activity.finish(), I think it will close all the activities. MAybe you can override the default function, and implement it in a static way, I'm not sure

Squ36
+1  A: 

I don't think you can do it in one line of code. Try opening your activities with startActivityForResult. As the result you can pass something like a CLOSE_FLAG, which will inform your parent activity that its child activity has finished.

That said, you should probably read this answer.

benvd
+2  A: 

just call the finish() in the method you would like to end the activity in, for example when you use the onCreate() method, in the end of the method, just add finish() and you will see the activity ends as soon as it is created!

Shouvik
+1  A: 

As per my knowledge, finish function close the current displayed screen only.

Refer this example (where see the answer given by 'plusminus'), it will sure help you to close your application.

PM - Paresh Mayani
+2  A: 

Hi,

That's one of most useless desires of beginner Android developers, and unfortunately it seems to be very popular. How do you define "close" an Android application? Hide it's user interface? Interrupt background work? Stop handling broadcasts?

Android applications are a set of modules, bundled in an .apk and exposed to the system trough AndroidManifest.xml. Activities can be arranged and re-arranged trough different task stacks, and finish()-ing or any other navigating away from a single Activity may mean totally different things in different situations. Single application can run inside multiple processes, so killing one process doesn't necessary mean there will be no application code left running. And finally, BroadcastReceivers can be called by the system any time, recreating the needed processes if they are not running.

The main thing is that you don't need to stop/kill/close/whatever your app trough a single line of code. Doing so is an indication you missed some important point in Android development. If for some bizarre reason you have to do it, you need to finish() all Activities, stop all Services and disable all BroadcastReceivers declared in AndroidManifest.xml. That's not a single line of code, and maybe launching the Activity that uninstalls your own application will do the job better.

ognian
A: 

Before doing so please read this other question too:

android.os.Process.killProcess(android.os.Process.myPid());
Pentium10