-3

I want to close my application when I click the button on the screen.

public WindowManager winManager;
public RelativeLayout wrapperView;
public Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams( WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);
    this.winManager = ((WindowManager)getApplicationContext().getSystemService(WINDOW_SERVICE));
    this.wrapperView = new RelativeLayout(getBaseContext());
    getWindow().setAttributes(localLayoutParams);
    View.inflate(this, R.layout.activity_main, this.wrapperView);
    this.winManager.addView(this.wrapperView, localLayoutParams);
    button1 = (Button)wrapperView.findViewById(R.id.button1);
    button1.setOnClickListener(mButton1_OnClickListener);
}

View.OnClickListener mButton1_OnClickListener = new View.OnClickListener() {
    public void onClick(final View v){
                winManager.removeView(wrapperView);
                wrapperView.removeAllViews();
                finish();
    }
};

I made this activity, but when I click on the button the application still appearing on recent apps menu and I don't know why.

tomss
  • 361
  • 3
  • 13

2 Answers2

0

Try this:

@Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        finish();
        System.exit(0);
    }
korunos
  • 768
  • 3
  • 11
  • 31
  • It still appearing on the recent apps menu. – tomss Dec 17 '15 at 12:09
  • What happens if you click in the recent apps menu? – korunos Dec 17 '15 at 12:10
  • On a button you want to Exit the application keep: android.os.Process.killProcess(android.os.Process.myPid()); Than define in Manifest activity Tag: – santoXme Dec 17 '15 at 12:20
  • @korunos It shows the open applications. That menu is where I can swipe the applications to close them. My application still appearing on that menu, – tomss Dec 17 '15 at 13:13
  • There is no way to exit the application in a way that it doen't appear in the recent apps menu because it's a system function! – korunos Dec 17 '15 at 13:14
0

Best approach is to take user to Launcher / Home.

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Refer this : https://stackoverflow.com/a/3226743/1283821

Community
  • 1
  • 1
Adhikari Bishwash
  • 2,770
  • 28
  • 32