Reputation: 1
I have created sub class of TabActivity
and it contains four TabHost
Tabs.
I just want to pick contact from my app, for this I am using the below code
private final int PICK = 2;
Intent intentContact = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
parentActivity.startActivityForResult(intentContact, PICK);
Android Contact Picker screen call successfully, when I tap to any contact it redirect me to the last screen of my app where I called it but onActivityResult
method does not get called.
In this regards I need your help. If I forget to mention anything please let me know.
Upvotes: 0
Views: 815
Reputation: 4255
Other way of doing is this...
1.On button click(which you want to open intent) open another activity.
2.On another activity's onCreate() open that intent.
3.onActivityResult set static data which is on previous activity and call finish().
4.This way no one ever know that you opened such a activity and you ll get your data.
:)
Upvotes: 0
Reputation: 1442
As you want here is some code stuff.
public class MyActivity extends TabActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// some other stuff
TabHost.TabSpec firstTab = tabHost.newTabSpec("firstTab");
firstTab.setContent(new Intent(this, FirstTabActivity.class)); // your class with content picker
tabHost.addTab(firstTab);
}
}
Here is an other
public class FirstTabActivity extends Activity
{
private static final int PICK_REQUEST_CODE = 2;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// some stuff
Button pickContactButton = findViewById(R.id.btn_pick_contact);
pickContactButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Intent intentContact = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intentContact, PICK_REQUEST_CODE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(PICK_REQUEST_CODE == requestCode && resultCode == RESULT_OK)
{
// do some stuff
}
}
}
Upvotes: 1
Reputation: 13647
The TabActivity has several strange behaviors, this might be one of them, you might workaround it to make it work, but I would definitely recommend you to start dropping it, it has been deprecated since API level 13. Read more about it: (https://developer.android.com/reference/android/app/TabActivity.html)
Upvotes: 0