Logout functionality in android

为君一笑 提交于 2019-12-04 14:54:31

use following for Logout.

yourintent.setflag(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);

It may help you

Simply give the intent to your login activity and put the flag in intent

inten1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

it will clear all the activities and navigate to ur login page.

This is a stack problem. You need to handle it. The best solution I found is that keep single activity in stack when your app runs and on log out only login screen will be in stack and if user presses back button, he will see Home screen.

What worked for me is keeping track of your login state internally, using some sort of global:

public boolean loggedin = false;

and then in all your activities, override onResume() and finish() if you're logged out:

@Override
public void onResume() {
  super.onResume();
  if (!loggedin)
    finish();
}

Try this:

Intent intent = new Intent(getApplicationContext(), Login.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
Toast.makeText(this, "Signed out", Toast.LENGTH_SHORT).show();
startActivity(intent);
finish();

First make these changes to your code

Intent intent = new Intent(getApplicationContext(),Login.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Then remove finish(); written inside your broadcast receiver. Best of luck.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!