-1

Because my application is fully dependent to SD memory, I want to close my application when SD card removed. I can find out when SD card removed but when I want to close my application using

System.exit(0)

application doesn't close and this error shown in my activity

appname isn't responding. Do you want to close it?

I guess its waiting for some processes to close. how can I fully close my application like in Task Manager. This is my code:

ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
am.killBackgroundProcesses("packegename");

System.runFinalizersOnExit(true);
System.exit(0);

Can anybody help me

UPDATE : I should say that I have two services running in background

Mojtaba Mahamed
  • 495
  • 2
  • 4
  • 18
  • did you use `finish();`? – Shayan Pourvatan Jan 01 '14 at 05:24
  • 2
    Do not invent your own ways to close the app, use `Activity.finish()`. Plus handle sd card removal properly, may be show a dialog to user that sd card is removed and now m gonna close. – M-Wajeeh Jan 01 '14 at 05:24
  • As M-WaJeEh posted, use `Activity.finish()` instead of `System.exit()` AND read over [Quitting an application - is that frowned upon](http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon) for why. – Tigger Jan 01 '14 at 05:31
  • I used finish() but it didn't work for me. I can use Activity.finish() but there are some services that I want to stop them. The services work with SD card – Mojtaba Mahamed Jan 01 '14 at 09:41

2 Answers2

1

Since your Facing Halting Problem ,I would suggest instead of killing the Background Process ,you can try to kill the app by using killProcess() as i shown below and then execute exit method in onDestory() of your activity.

android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
Sankar Ganesh PMP
  • 11,927
  • 11
  • 57
  • 90
0
System.runFinalizersOnExit(true); 

this will caused the system to finalize all the resources for this reason you are getting error.

Hope this will help you.

Muhammad Essa
  • 142
  • 1
  • 10