Reputation: 934
Fallowing is Home class. I am going to call Pick_contact intent. When ContactNumber view is clicked, device contact list is shown. And the result of picked contact is getting on TabGroupActivity.
public class Home extends Activity{
private static int PICK_CONTACT= 1;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
}
public void ContactNumber(View v)
{
Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
parentActivity = (TabGroupActivity)getParent();
parentActivity.startActivityForResult(intent, PICK_CONTACT);
}
}
My TabGroupActivity code is shown below.
public class TabGroupActivity extends ActivityGroup {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == PICK_CONTACT)
{
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
String cNumber="";
if (c.moveToFirst()) {
String id =c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
String hasPhone =c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (hasPhone.equalsIgnoreCase("1")) {
Cursor phones = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ id,
null, null);
phones.moveToFirst();
cNumber = phones.getString(phones.getColumnIndex("data1"));
System.out.println("number is:"+cNumber);
}
String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
QRCodeStaticData.qr_contents=name;
}
}
}
}
}
In this above code when user pick up contact from list, I want to open other child activity. But if user does not pick up contact and just cancel it, user will leave on the home activity. I am not getting how to call child activity inside TabGroupActivity after picking contact. I used below code to call child activity.
Intent intent = new Intent(getParent(), CreateQRCode.class);
TabGroupActivity parentActivity = (TabGroupActivity) getParent();
parentActivity.startChildActivity("CreateQRCode", intent);
But it does not work inside onActivityResult of TabGroupActivity.
Upvotes: 0
Views: 203
Reputation: 2664
Try this...Sorry for the Late Answer
In your TabGroupActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabHost = (TabHost) findViewById(android.R.id.tabhost);
// Adding the Activities to the tab view
// Blah Blah
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
System.out.println("Success");
if (requestCode == PICK_CONTACT) {
//Here you can launch the Child Activity according to the index
//Here CreateQRCode Activity index is 1 in the TabView
tabHost.setCurrentTab(1);
}
} else {
System.out.println("Fail");
}
}
In your HomeActivity
public void ContactNumber(View view) {
Intent intent = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
}
Upvotes: 1