Basically I have a screen that will either add or update a user contact information. The problem is I HAVE to use the same screen to do both things.
When a user selects “new” I simply pass the intent like this:
newButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent(ContactProjectActivity.this, AddContact.class);
startActivity(intent);
}
});
From a seperate activity, when the user selects “edit” I pass the intent like this:
edit.setOnClickListener(new Button.OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent(ContactView.this, AddContact.class);
intent.putExtra("name",personName.getText().toString());
startActivity(intent);
}
});
On the New/Edit page I have this code:
final Bundle extras = getIntent().getExtras();
String searchTerm = extras.getString("name");
if (extras.size() > 0) {
int index = searchTerm.indexOf(' ');
final String fName = searchTerm.substring(0, index);
final String lName = searchTerm.substring(index + 1, searchTerm.length());
With this code, I’m checking to see which activity is coming to my page. If I had information passed to me, I know I am supposed to edit the data.
The problem is, when I click the newButton in the ContactProjectActivity class my program crashes.
In you AddContact.class,you should have used:
instead of using