简体   繁体   中英

How to prevent user to go on previous activity after logged out in android using broadcast receiver?

I'm trying to make simple Login App using firebase as a backend, but I stuck on a problem that how to prevent user to go back on previous activities. So when I searched then I got the solution from here . But this time my app is running properly without any issue or crash but Logcat is saying to unregister the Broadcast Receiver.So I go through the Android official docs but I'm unable to do that. So please anyone help me out. The code has been given below.

Thanks in advance.

CODE FOR SENDING BROADCAST

Intent broadcastIntent = new Intent();                            
broadcastIntent.setAction("com.android.login.ACTION_LOGOUT");
sendBroadcast(broadcastIntent);

CODE FOR RECEIVING BROADCAST

IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("com.android.login.ACTION_LOGOUT");
    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d("onReceive","Logout in progress");
            //At this point you should start the login activity and finish this one
            finish();
        }

    },intentFilter);

Before finish(); call unregisterReceiver(this);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM