9

I can't seem to get ANY result when trying to start an activity from an activitygroup. I've put an onactivityresult in the activity and activitygroup? Specifically I'm trying to let the user choose a photo/video from the Intent.ACTION_GET_CONTENT, but I never get anything back? What am I doing wrong?

Here is how I call the code:

Intent pickMedia = new Intent(Intent.ACTION_GET_CONTENT);
   pickMedia.setType("video/*");
   startActivityForResult(pickMedia,12345);

Any ideas?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Matt
  • 161
  • 1
  • 3
  • Steven, Could you please provide a little more clarity as to what you mean via code? Thanks! – Jon Aug 25 '11 at 06:32
  • Jon - it looks like Nagkeeran used my approach to solve his issue. He posted some sample code at: http://stackoverflow.com/questions/6992142/android-wait-for-another-activity-result-it-didnt-work – Steven Pena Sep 16 '11 at 20:07

2 Answers2

41

I've had a similar issue. I had an ActivityGroup managing sub-activities. One of the sub-activities called a similar external intent (external to my app). It never called the onActivityResult within the sub-activity that started it.

I finally figured out/remembered that the issue is because Android will only allow a nested layer of sub-activities...ie sub-activities can't nest sub-activitites. To solve this:

  1. call getParent().startActivityForResult() from your sub-activity
  2. your parent (the activitygroup) will be able to handle the onActivityResult. So I created a subclass of ActivityGroup and handled this onActivityResult.
  3. You can re-route that result back to the sub-activity if you need to. Just get the current activity by getLocalActivityManager().getCurrentActivity() . My sub-activities inherit from a custom activity so I added a handleActivityResult(requestCode, resultCode, data) in that subclass for the ActivityGroup to call.
gnarf
  • 105,192
  • 25
  • 127
  • 161
Steven Pena
  • 1,184
  • 8
  • 18
  • 1
    i have same problem and i am not able to understand please can you explain it – Dharmendra Jul 01 '11 at 11:22
  • 1
    @Steven Pena, Then how you have called getDecorView() for startActivityForResult to get replace view of ActivityGroup – Vaibhav Jani Jul 01 '11 at 11:29
  • +1 That worked! I followed steps 1 and 2. After that I maintained a static reference to my current activity and propagated the result back there - kind of a hack but worked! Thanks! – Sagar Hatekar Aug 04 '11 at 16:20
4

In Your Parent Activity

protected void onActivityResult(int requestCode, int resultCode, Intent intent){
    if (requestCode == YOUR_REQUEST_CODE)   {

        CHILD_ACTIVITY_NAME activity = (CHILD_ACTIVITY_NAME)getLocalActivityManager().getCurrentActivity();

        activity.onActivityResult(requestCode, resultCode, intent);}}

So your childern activity's onActivityResult will run.

Omew
  • 41
  • 2