简体   繁体   English

登录后如何将android应用重定向到新页面

[英]How to redirect android app to new page after login

At the moment I have a login page that works, but when logged in correctly just displays a toast, I want to send the user to a new page that just displays 'Login successful'. 目前,我有一个可以正常使用的登录页面,但是如果正确登录,只会显示一个祝酒词,我想将用户引导到一个新页面,该页面仅显示“成功登录”。 Here is what I have so far: 这是我到目前为止的内容:

package com.example.loginscreen;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

   private EditText  username=null;
   private EditText  password=null;
   private TextView attempts;
   private Button login;
   int counter = 3;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      username = (EditText)findViewById(R.id.editText1);
      password = (EditText)findViewById(R.id.editText2);
      attempts = (TextView)findViewById(R.id.textView5);
      attempts.setText(Integer.toString(counter));
      login = (Button)findViewById(R.id.button1);
   }

   public void login(View view){
      if(username.getText().toString().equals("admin") && 
      password.getText().toString().equals("admin")){
      Toast.makeText(getApplicationContext(), "Redirecting...", 
      Toast.LENGTH_SHORT).show();
   }    
   else{
      Toast.makeText(getApplicationContext(), "Wrong Credentials",
      Toast.LENGTH_SHORT).show();
      attempts.setBackgroundColor(Color.RED);   
      counter--;
      attempts.setText(Integer.toString(counter));
      if(counter==0){
         login.setEnabled(false);
      }

   }

}
   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
   }

}

Used Explicit Intent for this like 像这样使用Explicit Intent

 Intent I=new Intent(loginPage.this, HomePage.class);
 startActivity(I);

You must have Activity with name HomePage register in your manifest.xml 您的manifest.xml必须具有名称为HomePage register的Activity

Look at 看着

@Resources @资源

You can start a activity Through Intent 您可以通过意图开始一项活动

Intent I=new Intent(loginPage.this, NewPage.class); startActivity(I);

By This way You will Move from LoginPage to NewPage 这样,您将从LoginPage移到NewPage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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