-1

I have the following case

When press a button I startActivityForResult , it opens another activity with dialog theme and show a list of linear layouts, and when I press on the linear layout I finish the activity on the onClick Listener

but the onActivityResult method never called

so can anyone help in this ??

EDIT: Adding code

Activity that open the dialog activity

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtra(DATA_LIST_KEY, myDataList);
startActivityForResult(intent, 5000);

onClick Listener

public void onClick(View v) {

   setResult(5000);
   SecondActivity.this.finish();                        
}

EDIT 2

I have found the following

1- I'm using TabActivity to add tabs to all my activities, now The onActivityResult fire on the TabActivity but doesn't fire in the sub activities inside it

Can any one help ??

Amira Elsayed Ismail
  • 9,216
  • 30
  • 92
  • 175

3 Answers3

2

Make sure you call setResult(intent) method in the second activity after clicking the item.

Edit 1: I think you set the result in a wrong way. It should be an intent with either Result_OK or Reuslt_Cancel.

Edit 2- Example:

Intent output = new Intent();
output.putExtra(key, val);
setResult(RESULT_OK, output)
MSaudi
  • 4,442
  • 2
  • 40
  • 65
0

Hints to check:

  1. You call setResult before finish().

  2. Remove android:launchMode="singleInstance" or android:noHistory for your activity if present

marcinj
  • 48,511
  • 9
  • 79
  • 100
  • Yes I call setResult before calling finish, and I didn'y add android:launchMode="singleInstance" or android:noHistory to my manifest file – Amira Elsayed Ismail Mar 05 '14 at 10:49
  • then, your code looks fine, I would actually call SecondActivity.this.setResult(RESULT_OK), this 5000 will be returned as request code in onActivityResult – marcinj Mar 05 '14 at 10:56
  • Why do you need `SecondActivity.this.` anyway? – marcinj Mar 05 '14 at 10:56
  • because the code is inside OnClick Listener, so I prefer to make sure that I'm accessing the right object, and I think this is not the problem here – Amira Elsayed Ismail Mar 05 '14 at 12:20
  • You have added info that you are using TabActivity - look into this answers: http://stackoverflow.com/questions/11556684/issue-with-onactivityresult-in-tab-activity – marcinj Mar 05 '14 at 12:59
0

I have figure out the reason of this problem, I was using TabActivity and using activities as tabs and the onActivityResult called but in the parent activity that hold all other activities and I have solved it by handling it in the parent activity

Amira Elsayed Ismail
  • 9,216
  • 30
  • 92
  • 175