Logout from the application Android

前端 未结 7 1922
旧巷少年郎
旧巷少年郎 2020-12-25 08:43

I have tried to logout from my app when the user clicks on Logout.It is working fine in case the user after login without closing the app if he doed logout .Then it is worki

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-25 08:56

    case R.id.drawer_item_logout: //name of logout button

                        AlertDialog.Builder builder=new AlertDialog.Builder(Home.this); //Home is name of the activity
                        builder.setMessage("Do you want to exit?");
                        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int id) {
    
                                finish();
                                Intent i=new Intent();
                                i.putExtra("finish", true);
                                i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // To clean up all activities
                               //startActivity(i);
                                finish();
    
                            }
                        });
    
                        builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
    
                            AlertDialog alert=builder.create();
                        alert.show();
    
    
                        break;
    

    [1]

提交回复
热议问题