Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在用户停用帐户后关闭应用程序?_Java_Android - Fatal编程技术网

Java 如何在用户停用帐户后关闭应用程序?

Java 如何在用户停用帐户后关闭应用程序?,java,android,Java,Android,在我的应用程序中,我必须创建停用代码这是我的代码 @Override protected void onCreate(Bundle savedInstanceState) { context = getApplicationContext(); dbHelper = new DatabaseHelper(context); userMO = dbHelper.getRingeeUserData(1); super.onCre

在我的应用程序中,我必须创建停用代码这是我的代码

@Override
    protected void onCreate(Bundle savedInstanceState) {
        context = getApplicationContext();
        dbHelper = new DatabaseHelper(context);
        userMO = dbHelper.getRingeeUserData(1);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.manage_account);


        TextView deleteAccount = (TextView) findViewById(R.id.delete_account);
        deleteAccount.setOnClickListener(new View.OnClickListener() {
         // while clicking Delete My Account this method is called

           @Override
            public void onClick(View arg0) {
                AlertDialog.Builder alertDialog = new AlertDialog.Builder(ManageAccount.this);
                alertDialog.setTitle("Confirm Deactivate");
                alertDialog.setMessage("Are you really want to deactivate your account?");
                alertDialog.setNegativeButton("YES", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //while clicking YES button isDelete is stored as 1 in database
                        userMO.setIsDelete(1);
                        del();
                         new AsyncTask<Void, Void, String>() {
                            protected String doInBackground(Void... arg0) {
                                return userDelegate.updateUser(userMO, context);

                            }

                        }.execute(null, null, null);
                        dbHelper.updateRingeeUser(1, userMO.getRingeeUserId(), userMO);
                        Toast.makeText(getApplicationContext(), "successfully deactivated", Toast.LENGTH_SHORT).show();

                    }
                });

                alertDialog.setPositiveButton("NO", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                // Showing Alert Message
                alertDialog.show();
            }

        });

    }
@覆盖
创建时受保护的void(Bundle savedInstanceState){
context=getApplicationContext();
dbHelper=新数据库助手(上下文);
userMO=dbHelper.getRingeeUserData(1);
super.onCreate(savedInstanceState);
setContentView(R.layout.manage_账户);
TextView deleteCount=(TextView)findViewById(R.id.delete_帐户);
deleteAccount.setOnClickListener(新视图.OnClickListener(){
//单击“删除我的帐户”时,将调用此方法
@凌驾
公共void onClick(视图arg0){
AlertDialog.Builder AlertDialog=新建AlertDialog.Builder(ManageAccount.this);
alertDialog.setTitle(“确认停用”);
setMessage(“您真的想停用您的帐户吗?”);
alertDialog.setNegativeButton(“是”,新的DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface dialog,int which){
//单击“是”按钮时,isDelete在数据库中存储为1
userMO.setIsDelete(1);
del();
新建异步任务(){
受保护的字符串doInBackground(无效…arg0){
返回userDelegate.updateUser(userMO,context);
}
}.执行(空,空,空);
dbHelper.UpdateringeUser(1,userMO.getRingeeUserId(),userMO);
Toast.makeText(getApplicationContext(),“已成功停用”,Toast.LENGTH_SHORT.show();
}
});
alertDialog.setPositiveButton(“否”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
dialog.cancel();
}
});
//显示警报消息
alertDialog.show();
}
});
}
单击管理帐户-->删除我的帐户-->此处为是/否如果用户单击“是”按钮,则删除将作为1(数据库中的用户已禁用)存储在此处的数据库中。此外,我必须关闭该应用程序,并带出手机的正常主页
有人能帮我吗

我认为您不应该在停用account后关闭应用程序,而是将用户返回到您的登录屏幕:

Intent reLoginIntent = new Intent(context, Login.class);

reLoginIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);

startActivity(reLoginIntent);

finish();
如果您只想关闭活动,只需使用:

finish();

单击“是”后是否要重新启动应用程序?单击“是”按钮后,应用程序将被停用,但在单击应用程序应关闭(单击“是”后,应用程序窗口不应显示)后,请尝试以下操作:Toast.make。。。MainActivity.this.finish();感谢您在这段代码中的响应。您为MainActivity声明了什么?但我必须在哪里添加finish();这取决于你的需要,你应该把它放在你希望活动完成的地方和时间。我认为您的代码中有一个错误的假设,因为您使用了AsyncTask,然后在实际操作不一定完成时进行了Toast。非常感谢您,我尝试了您提供的第一个代码,它工作得非常好,很高兴它起到了帮助作用。如果它解决了您的问题,您能标记答案吗?我只是在toast运行(成功停用)后添加了您的代码(第一个),并按照您所说的从我的项目中调用了登录活动