0

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;
   }

}
1
  • 1
    create new intent startt activity
    – sakir
    Jun 12, 2014 at 10:14

2 Answers 2

3

Used Explicit Intent for this like

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

You must have Activity with name HomePage register in your manifest.xml

Look at

@Resources

5
  • would Test.class be a new activity I create? Jun 12, 2014 at 10:15
  • so HomePage would be the activity you're redirected to? Jun 12, 2014 at 10:18
  • 1
    @user3478524 exactly. This HomePage you can replace with the name of your target-activity. Jun 12, 2014 at 10:19
  • @user3478524 ya exactly. go to any tutorial link.
    – M D
    Jun 12, 2014 at 10:19
  • I created the activity to be sent to correctly, but when I add in Intent I=new Intent(loginPage.this, HomePage.class); startActivity(I); the app just fails after I enter login details Jun 12, 2014 at 11:12
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.