IodineAuthUtils.java 文件源码

java
阅读 22 收藏 0 点赞 0 评论 0

项目:thyroxine 作者:
/**
 * Attempts to log out by removing the current Iodine account.
 * This method does not change state on the server.
 * After finishing, this method will call finish() on the passed activity.
 * @param activity The activity used as a context.
 */
public static void attemptLogout(@NonNull final Activity activity) {
    final AccountManager am = AccountManager.get(activity);
    final Account account = getIodineAccount(activity);
    final AccountManagerCallback<Boolean> callback = new AccountManagerCallback<Boolean>() {
        @Override
        public void run(AccountManagerFuture<Boolean> future) {
            try {
                Boolean result = future.getResult();
                if (!result) {
                    throw new Exception("Result is false");
                }
            } catch (Exception e) {
                Log.e(TAG, "Error trying to remove account", e);
                String message = activity.getString(R.string.error_removing_account, e.toString());
                Toast.makeText(activity, message, Toast.LENGTH_SHORT).show();
                return;
            }
            Log.i(TAG, "Successfully removed account.");
            Toast.makeText(activity, R.string.sign_out_success, Toast.LENGTH_LONG).show();
        }
    };

    am.removeAccount(account, callback, null);
    activity.finish();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号