我正在使用導航抽屜來顯示所有項目,如Setting, Profile, Contact Us, About Us, Logout
單擊這些項目時,它應顯示在片段或其他活動中。創建應用程序註銷事件
我試圖創建Logout Fragment
,但它沒有使用活動&意圖。
我怎樣才能得到註銷時,它應該從應用程序完全註銷,就像它發生在任何銀行應用程序。
我正在使用導航抽屜來顯示所有項目,如Setting, Profile, Contact Us, About Us, Logout
單擊這些項目時,它應顯示在片段或其他活動中。創建應用程序註銷事件
我試圖創建Logout Fragment
,但它沒有使用活動&意圖。
我怎樣才能得到註銷時,它應該從應用程序完全註銷,就像它發生在任何銀行應用程序。
你並不需要爲註銷片段,在註銷的點擊只需要運行下面的代碼
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
我應該在NavigationDrawer中加入嗎?公共布爾onNavigationItemSelected(MenuItem項目){ //處理導航視圖項目點擊這裏。 android.app.Fragment fragment = null; int id = item.getItemId(); if(id == R.id.nav_logout){................. Here ............} – Priyanka
我創建對話框如下:單擊該菜單項
public void logoutDialog() {
/**
* Create Alert DialogBuilder */
final AlertDialog.Builder logoutAlert = new AlertDialog.Builder(this);
final RowLogoutDialogsBinding logoutDialogsBinding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.row_logout_dialogs, null, false);
View logoutView = logoutDialogsBinding.getRoot();
logoutAlert.setView(logoutView);
/*
* Create Alert Dialogs */
final AlertDialog mLogoutDialog = logoutAlert.create();
mLogoutDialog.setTitle(getString(R.string.logout_dialog_title));
mLogoutDialog.show();
/*
* Layout for dialog */
setFontFace(logoutDialogsBinding.logoutMessage);
logoutDialogsBinding.logoutNo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mLogoutDialog.dismiss();
}
});
logoutDialogsBinding.logoutYes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mLogoutDialog.dismiss();
AccountAuthenticator.removeAccount(mContext);
finish();
// DO OTHER PROCESS OF LOGOUT like clear PREFERENCE, DB
Toast.makeText(mContext, R.string.string_loggedout_success, Toast.LENGTH_SHORT).show();
}
});
}
,我剛打開那個對話框。
case R.id.nav_logout:
logoutDialogs();
break;
希望它能幫助你。
分享你註銷的代碼,不清楚 –
@jainishkapadia請不要在問題中加上「致以致謝」 –
把你的代碼.. –