[英]Google sign-in in android app
我對android應用中的google登錄有一個非常普遍的問題。
可以說我在我的android設備上使用xxx@gmail.com作為帳戶。 我通過此帳戶在android應用程序(com.test.app)中登錄。
現在,我從設備上刪除了該帳戶。
問題:是否應該從com.test.app中注銷? (建議)
自我挖掘在我所見過的幾乎所有應用中,它都不會注銷。
使用SessionManager
和SharedPreferences
在XML中創建一個按鈕,並在其上添加OnClick事件。
然后
session = new CustomSessionManager(getApplicationContext());
session.logoutUser();
這是我的CustomSessionManager
類。
public class CustomSessionManager {
// Shared Preferences
SharedPreferences pref;
// Editor for Shared preferences
SharedPreferences.Editor editor;
// Context
Context _context;
// Shared pref mode
int PRIVATE_MODE = 0;
// Sharedpref file name
private static final String PREF_NAME = "Amiyo";
// All Shared Preferences Keys
private static final String IS_LOGIN = "IsLoggedIn";
// User name (make variable public to access from outside)
// public static final String KEY_NAME = "name";
// Email address (make variable public to access from outside)
public static final String KEY_EMAIL = "UserEmail";
// Constructor
public CustomSessionManager(Context context){
this._context = context;
pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = pref.edit();
}
/**
* Create login session
* */
public void createLoginSession(String UserEmail){
// Storing login value as TRUE
editor.putBoolean(IS_LOGIN, true);
// Storing name in pref
// editor.putString(KEY_NAME, name);
// Storing email in pref
editor.putString(KEY_EMAIL, UserEmail);
// commit changes
editor.commit();
}
/**
* Clear session details
* */
public void logoutUser(){
// Clearing all data from Shared Preferences
editor.clear();
editor.commit();
// After logout redirect user to Loing Activity
Intent i = new Intent(_context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
// Closing all the Activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
// Add new Flag to start new Activity
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Staring Login Activity
_context.startActivity(i);
}
/**
* Quick check for login
* **/
// Get Login State
public boolean isLoggedIn(){
return pref.getBoolean(IS_LOGIN, false);
}
}
有關更多詳細信息,請訪問此處http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.