1

In my project I show the contact screen, When I click any contact then it should go back to my dummy screen where I need to show selected contact.

Now problem is When I click from my project contact list and selected the contact it always comes to my Dummy project screen but data always comes as null. Not getting why its comes as null. In my project for showing the contact screen we followed the lot of path.

1 HomeActivity->TabActivity->HomeTabFragment->BuddyFragment(For showing the contact screen )

In Buddy fragment I wrote the following code:

 Intent intent = new Intent();

 intent.putExtra("chaton_buddy_number", buddy.getNo());
 intent.putExtra("chaton_buddy_name", buddy.getName());

 getActivity().setResult(Activity.RESULT_OK, intent);

 getActivity().finish();
 return true;

and in dummyApplication I wrote the following code.

public class MainActivity extends Activity { 
TextView tv; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
tv = (TextView)findViewById(R.id.textView1); 
Button button =(Button)findViewById(R.id.button1); 
button.setOnClickListener(new Button.OnClickListener() {

         @Override
         public void onClick(View v) {
              Intent intent = new Intent();
              intent.setAction(Intent.ACTION_SEND);
              intent.putExtra("mChatONBuddies", true);

    //Launching HomeActivity of my project because that one is the first activity. 
    //intent.setComponent(new ComponentName("com.sec.myproject", "com.sec.chaton.HomeActivity"));

            startActivityForResult(intent, 0);
        }
    });
}

Intent (data) always come in on my dummy project screen.

I tried following things but did not helped me.

  1. calling getParent().getAcitivity().setResult(Activity_ResultOK, intent)
  2. Removed the Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP wherever its used. Its also not working

any other suggestion is highly appreciated.

2
  • does the manifest of BuddyFragment's activity also have singletop? does the onActivityResult return immediately or after quitting the Buddyfragment?
    – nandeesh
    Oct 26, 2012 at 5:01
  • actually buddyfragment is an android fragment which launch through tabActivity... In tabActivity they were setting the SINGLE_TOP, I removed it but stills not working.... Oct 26, 2012 at 7:41

1 Answer 1

0

I am fan of interface when doing such callbacks

If you want your fragment should pass data back to its containing activity then consider using interface to handle and pass the data.

Step1

Declare following interface in your fragment

public interface iContactHelper {
    public void onSelectContact(String contactNumber,String contactName);
}

Step2

Declare follwoing in your Fragment.

iContactHelper icontactHelper;

@Override
public void onAttach(Activity a) {
    super.onAttach(a);
    icontactHelper = (icontactHelper) a;
}

Step3

When you need to send contact information to container activity,call following.

iContactHelper.onSelectContact(buddy.getNo(),buddy.getName());

Step4

Finally have your container activity implement the iContactHelper interface

@Override
public void onSelectContact(String contactNumber,String contactName) {
    Log.d("LOG","Contact Name " + contactName);
    Log.d("LOG","Contact Number " + contactNumber);
}
1
  • 1
    I could not understand what you try to convey it...Can you please ellobrat more Oct 26, 2012 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.