安卓退出登录功能
退出登录功能基本上每个app都需要用到的我这里介绍一种使用广播退出登录
1.在退出登录的页面上发送一个广播
Intent intent =new Intent();
intent.setAction("exit_app");
sendBroadcast(intent);
startAct(LoginActivity.class);
2,在所以继承的baseactivity接收广播
private MyReceiver receiver;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerBroadcast();
}
private void registerBroadcast() {
// 注册广播接收者
receiver =new MyReceiver();
IntentFilter filter =new IntentFilter();
filter.addAction("exit_app");
mContext.registerReceiver(receiver,filter);
}
class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("exit_app")){
// LogUtils.e("zs","退出登陆");
finish();
}
}
}