Good morning I'm trying to pass 2 data from one activity to another but I'm not getting below the relevant code in the first Activity:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = getContentResolver().query(contactData, null, null, null, null);
if (c.moveToFirst()) {
String phoneNumber="";
String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String contactId = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
String hasPhone = c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if ( hasPhone.equalsIgnoreCase("1"))
hasPhone = "true";
else
hasPhone = "false" ;
if (Boolean.parseBoolean(hasPhone))
{
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);
while (phones.moveToNext())
{
phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
phones.close();
Bundle bundle = new Bundle();
bundle.putString(name, String.valueOf(name));
bundle.putString(phoneNumber, String.valueOf(phoneNumber));
}
//mainActivity.onBackPressed();
// Toast.makeText(mainactivity, "go go go", Toast.LENGTH_SHORT).show();
// tvname.setText("Name: "+name);
// tvphone.setText("Phone: "+phoneNumber);
// Log.d("curs", name + " num" + phoneNumber);
}
c.close();
}
finish();
}
Below is the relevant Second Activity code:
intent = getIntent();
Bundle getBundle = null;
getBundle = intent.getExtras();
Bundle bundle = intent.getExtras();
String name = bundle.getString("name");
String phone = bundle.getString("phoneNumber");
messageContact = name+'\n'+ phone;