Android judge login

Whether to screen login

/**
 * 测试是否登陆
 */
loginButton.setOnClickListener(new OnClickLoginedListener(mContext) {
 /**
 * 自定义实现的抽象方法,用于判断当前设备是否登录
 */
 @Override
 public boolean isLogined(Activity context,View view) {
 return false;
 }
 /**
 * 主要用于执行判断用户登录后执行的逻辑
 */
 @Override
 public void onLoginedClick(View v) {
 Toast.makeText(mContext,"设备已登录,之后后续操作...",Toast.LENGTH_LONG).show();
 }
 /**
 * 主要用于执行判断用户登录后执行的逻辑
 */
 @Override
 public void onNoLoginedClick(View v) {
 Toast.makeText(mContext,"设备未登陆,无法执行后续操作...",Toast.LENGTH_LONG).show();
 }
});

Click the button to listen for login

/**
 * 判断当前App用户是否登录的监听源码
 */
public abstract class OnClickLoginedListener extends BaseClickListener {
 private Activity context = null;
 public OnClickLoginedListener(Activity context) {
 this.context = context;
 }
 @Override
 public void onClick(View view) {
 super.onClick(view);
 if (isLogined(context,view)) {
 onLoginedClick(view);
 } else {
 onNoLoginedClick(view);
 }
 }
 /**
 * 判断当前用户是否登录
 * @param context
 * @param view
 * @return
 */
 public abstract boolean isLogined(Activity context,View view);
 /**
 * 用户登录后执行的逻辑
 * @param v
 */
 public abstract void onLoginedClick(View v);
 /**
 * 用户登录执行点击事件
 */
 public abstract void onNoLoginedClick(View v);
}

realization

Summary: this method is used to return the logical judgment of whether the user logs in, and it is also an abstract method. Therefore, we also need to implement its specific logic in the business layer. Then we rewrite the onloginedclick method and onnologinedclick method, in which the onloginedclick method is the callback method after the user logs in, The onnologinedclick method is the callback method executed after the user is not logged in

summary

The above is the Android login judgment introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support to our website! If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>