0

I Have developed a android application. In that application I have exit button, I want to exit from my application when I press the EXIT BUTTON. please someone give me a sample code or a tutorial link.

4 Answers4

1

Read (When to Include an Exit Button in Android Apps (Hint: Never)), this article explain you what you need to do and what need not.

Some extract

So, when should your app include an exit button?

The Short Answer

Never.

The Long Answer

Your app doesn't need an exit button. It really doesn't. Arguments to the contrary can generally be summarized as:

  • Users expect it.

  • It's a way to let users say "stop doing everything and stop consuming juice".

Vinayak Bevinakatti
  • 40,205
  • 25
  • 108
  • 139
0

call finish() on the onClick() method of your button

sachy
  • 739
  • 7
  • 13
  • when i call finish() method within app, it exits only my current page. but i want to exit from my application when i press the Exit button. –  May 09 '12 at 09:26
  • You have to call finish() of your main(first) activity i.e. the activity whose category is of `android.intent.category.LAUNCHER` type in manifest file – sachy May 09 '12 at 09:41
0

Set finish() method on your button click event like..

 btn.setOnClickListener(new OnClickListener() {    
        @Override
        public void onClick(View v) {
                    finish();
             }
      });
SBJ
  • 4,089
  • 3
  • 24
  • 27
Jackson Chengalai
  • 3,907
  • 1
  • 24
  • 39
-1

If you want close specific activity use finish or if you want to remove stack from Android process use the following code:

    android.os.Process.killProcess(android.os.Process.myPid());
            super.onDestroy();



    protected void onCreate(Bundle savedInstanceState) { 

    this.setContentView(R.layout.layoutxml); 

    this.ExitButton = (Button)this.findViewById(R.id.close); 

    this.ExitButton.setOnClickListener(new OnClickListener() { 

    @Override 

    public void onClick(View v) { 

    finish(); // for stopping Current Activity 

    } 

    });

    // add this line forStoping Entire Application  to Close 
    @Override
        protected void onDestroy() {
    // closing Entire Application
            android.os.Process.killProcess(android.os.Process.myPid());
            super.onDestroy();
        }
    }
Flexo
  • 87,323
  • 22
  • 191
  • 272
sravan
  • 5,303
  • 1
  • 31
  • 33