I am trying to call other activity to get the result from main activity for contact number. Once the onActivityresult assign the value to contactNo, sending sms message.
However my problem is smsmanager code after getContactselect() method is invoked immediately before the onActivityResult completes. because of this contact number is assigned as null.
Main Activity code:
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Object o = lv1.getItemAtPosition(position);
ItemDetails obj_itemDetails = (ItemDetails)o;
...
...
**getContactselect();**
**smsManager.sendTextMessage(contactNo, null, obj_itemDetails.getMessage(), null, null);**
}
...
public void getContactselect() {
Intent ourIntent = new Intent(BreakOut.this,ContactsSelector.class);
startActivityForResult(ourIntent,CONTACT_SELECT);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
switch(requestCode) {
case CONTACT_SELECT:
if (resultCode == RESULT_OK) {
contactNo = data.getStringExtra("ContactDetails");
Toast.makeText(this, "You have chosen the contact: " + " " + contactNo, Toast.LENGTH_LONG).show();
break;
}
}
}