Nik
Nik

Reputation: 7214

onActivityResult() is never call in nested Activity

I have the next UI hierarhy:

FragmentActivity -> Fragment with TabHost and LocalActivityManager -> MyNestedActivity

MyNestedActivity places in single tab in Fragment. When I call startActivityForResult() in MyNestedActivity, Activity starts normally, but onActivityResult() in never called.

But if I open MyNestedActivity using startActivity(), onActivityResult() works fine.

When I must hook onActivityResult()? In FragmentActivity on in Fragment? How I must dispatch result to my MyNestedActivity?

SOLVED:

In this UI hierarhy onActivityResult() not called. I just change MyNestedActivity to Fragment and my hierarchy become FragmentActivity -> Fragment. Now onActivityResult() works fine.

Upvotes: 0

Views: 1983

Answers (3)

Nik
Nik

Reputation: 7214

onActivityResult() in nested Activity not call by Android.

The correct way to get activity result in nested activity is:

  1. startActivityForResult() from host Activity (not from nested!),

  2. receive Activity result in host Activity,

  3. dispatch Activity result to nested Activity.

Upvotes: 2

bk138
bk138

Reputation: 3088

We had this https://groups.google.com/forum/?fromgroups=#!topic/android-developers/65oLmvIlgFM problem and solvedit by changing the activities launchMode to something other that singleInstace or singleTask.

Upvotes: 0

Cyril Leroux
Cyril Leroux

Reputation: 2629

If you want to call startActivityForResult() from a Fragment you have to set the onActivityResult() method in the Fragment class and not in the host Activity. See this link for more informations.

Upvotes: 0

Related Questions