在我的应用中,我必须创建停用代码,这是我的代码
@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();
}
});
}
点击管理帐户后 - &gt;删除我的帐户 - &gt;是/否如果用户单击是按钮,IsDelete将在数据库中存储为1(用户在数据库中禁用)此处此外我必须关闭该应用程序并且必须携带移动设备的正常主页 任何人都可以帮助我?
答案 0 :(得分:2)
我认为您在停用帐户后不应该关闭应用程序,而是将用户返回到您的登录屏幕:
Intent reLoginIntent = new Intent(context, Login.class);
reLoginIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(reLoginIntent);
finish();
如果您只想关闭活动,只需使用:
finish();