I've created a login screen as below:
public class LapMasterActivity extends Activity
{
@override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.lap_master, menu);
return true;
}
//Do once the "Login" button is clicked
public void onClick(View view)
{
//get the users name and password
EditText editName = (EditText) findViewById(R.id.txtUserName);
String name = editName.getText().toString();
//EditText editPassword = (EditText) findViewById(R.id.txtUserPassword);
//String password = editPassword.getText().toString();
//create an Intent object and pass it the name and password
Intent intent = new Intent(this, UserLoggedInScreen.class);
intent.putExtra("userName", name);
//intent.putExtra("userPassword", password);
startActivity(intent);
}
}
I'm trying to put the data into an Intent Object and pass it to UserLoggedInScreen. The txtUserName is the ID for the text part where a user puts their name.
In the UserLoggedInScreen class I then try to get the Intent Object data:
public class UserLoggedInScreen extends Activity
{
TextView welcomeUser;
@override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.userloggedinscreen);
//get the Intent Object from LapMasterActivity
Intent intent = getIntent();
//get the data from the Intent Object
String userName = intent.getStringExtra("userName");
//String userPassword = intent.getStringExtra("userPassword");
welcomeUser = (TextView) findViewById(R.id.userName);
welcomeUser.setText(userName);
}
The userName is the ID for the text that says User Name and I have also tried using txtUserName.
This results in "Unfortunately LapMaster has stopped working".
I've asked on stackoverflow but thought I'd have a go on here too.
Thanks.
public class LapMasterActivity extends Activity
{
@override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.lap_master, menu);
return true;
}
//Do once the "Login" button is clicked
public void onClick(View view)
{
//get the users name and password
EditText editName = (EditText) findViewById(R.id.txtUserName);
String name = editName.getText().toString();
//EditText editPassword = (EditText) findViewById(R.id.txtUserPassword);
//String password = editPassword.getText().toString();
//create an Intent object and pass it the name and password
Intent intent = new Intent(this, UserLoggedInScreen.class);
intent.putExtra("userName", name);
//intent.putExtra("userPassword", password);
startActivity(intent);
}
}
I'm trying to put the data into an Intent Object and pass it to UserLoggedInScreen. The txtUserName is the ID for the text part where a user puts their name.
In the UserLoggedInScreen class I then try to get the Intent Object data:
public class UserLoggedInScreen extends Activity
{
TextView welcomeUser;
@override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.userloggedinscreen);
//get the Intent Object from LapMasterActivity
Intent intent = getIntent();
//get the data from the Intent Object
String userName = intent.getStringExtra("userName");
//String userPassword = intent.getStringExtra("userPassword");
welcomeUser = (TextView) findViewById(R.id.userName);
welcomeUser.setText(userName);
}
The userName is the ID for the text that says User Name and I have also tried using txtUserName.
This results in "Unfortunately LapMaster has stopped working".
I've asked on stackoverflow but thought I'd have a go on here too.

Thanks.