Android Activity Flow (Login or Register and go to Home)

时光总嘲笑我的痴心妄想 提交于 2019-12-01 08:44:59

You can finish your main activity just after you navigate to home/login screen ex:

Intent intent=new Intent(this,Home.class);
startActivity(intent);
finish();

By doing this if user presses a back button on login or home page blank page wont be visible.

Also you can use your main activity as splash screen where you show some image and in background decide to go to login/home activity.

Vimal Rughani

If you wish you put login screen as dialog box, which may help you. For creating login dialog you can use below code.

// Create Object of Dialog class
final Dialog login = new Dialog(this);
// Set GUI of login screen
login.setContentView(R.layout.login_dialog);
login.setTitle("Login to Pulse 7");

// Init button of login GUI
Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
Button btnCancel = (Button) login.findViewById(R.id.btnCancel);

 // Attached listener for login GUI button
 btnLogin.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Toast.makeText(Pulse7LoginDialogActivity.this,
               "Login Sucessfull", Toast.LENGTH_LONG).show();
   }
});
btnCancel.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
       login.dismiss();
   }
 });

 // Make dialog box visible.
 login.show();

This code can be used...

      Intent intent=new Intent(this,Home.class);
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
      startActivity(intent);
      finish();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!