@Override
public void onActivityResult(int reqCode, int resultCode, **Intent data**){
super.onActivityResult(reqCode, resultCode, **data**);
switch (reqCode) {
case (PICK_CONTACT) :
if (resultCode == Activity.RESULT_OK) {
Uri contactData = **data**.getData();
Cursor c = getContentResolver().query(**contactData**, null, null, null, null);
if (c.moveToFirst()) {
String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
// TODO Whatever you want to do with the selected contact name.
//ImageView imageView = (ImageView)findViewById(R.id.imageView);
//Picasso.with(this).load("https://cms-assets.tutsplus.com/uploads/users/21/posts/19431/featured_image/CodeFeature.jpg").into(imageView);
FragmentManager FM = getFragmentManager();
FragmentTransaction FT = FM.beginTransaction();
FragmentActivity F1 = new FragmentActivity();
FT.add(R.id.frame_layout, F1);
FT.commit();
}
}
break;
}
}
Can someone explain how the data
variable in the onActivityResult
argument is used to make this code work?
I see that the variable is used to call getData()
but I'm confused as to how this variable is connected to the Intent outside of this method.
Furthermore, what exactly does calling data.getData()
do ?
Basically I'm trying to understand this snippet of the code
public void onActivityResult(int reqCode, int resultCode, Intent data){
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case (PICK_CONTACT) :
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = getContentResolver().query(contactData, null, null, null, null);
Could anyone help me make sense of it?