Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android kill process [duplicate]

How to kill whole application in onne single click.. finish() is not working?? it redirects to tha previous activity...pls guide me.

          public void onClick(View arg0) {
            // TODO Auto-generated method stub
            WallpaperManager wp = WallpaperManager
                    .getInstance(getApplicationContext());

            try {
                Display d = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
                        .getDefaultDisplay();
                int width = d.getWidth();
                int height = d.getHeight();
                wp.setBitmap(b1);
            } catch (IOException e) {
                Log.e("error", "Cannot set image as wallpaper", e);
            }

                        finish();

        }
like image 802
Coder Avatar asked May 31 '13 07:05

Coder


2 Answers

System.exit() does not kill your app if you have more than one activity on the stack

Use android.os.Process.killProcess(android.os.Process.myPid()); this way.

for sample

public void onBackPressed() {
    android.os.Process.killProcess(android.os.Process.myPid());
    super.onBackPressed();
}

For more detail see Is quitting an application frowned upon? , How to force stop my android application programmatically?

I hope this will help you.

like image 183
Gunaseelan Avatar answered Sep 28 '22 16:09

Gunaseelan


You can use this function to close your application

Process.killProcess( Process.myPid() ); 
like image 36
Mukesh Kumar Singh Avatar answered Sep 28 '22 16:09

Mukesh Kumar Singh