android - OnActivityResult Doesn't work with activityGroup -
im app use tabhost. , activitygroup load activities under tab. on 2nd tab open activitygroup "tabgroupactivity"... , here open child activity "childactivity2". "childactivity2" want open normal activity has theme dialog. , when return normal activity want run onactivityresult() in childactivity2. onactivityresult() in childactivity2 not working.
the code in childactivity2 start normal activity is
data.putint("doctorid", doctor_id); intent createschedule = new intent(scheduleweekly.this, createschedule.class).putextras(data); startactivityforresult(createschedule, 1);
this onactivityresult()
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); if(resultcode==activity.result_ok) { log.e("get","result"); ................. ...... } }
your problem same mine. problem onactivityresult function won't directly trigger child activity in activity group, intent child activity.
the solution divided in 3 steps.
first, have let parent activity, activiygroup class call startactivityforresult function in position need jump out current activity. in child activity, when need lunch normal activity, instead call:
startactivityforresult(intent, 0);
you should call:
getparent().startactivityforresult(intent,0);
this let activitygroup take care of call back. in case, since have 3 level nested, may have try whether parent or grandparent should take care of call , make proper modification getparent() part.
second, after make parent class of current activity start intent, need add onacivityresult() function both parent class , current child class. in current class write normal call handle message now. in parent class, onactivityresult() function catch call normal activity , deliver intent current class.
third, step parent onactivityresult class, in class, need:
public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); switch (resultcode) { case result_ok: mychildactivity ca = (mychildactivity) getlocalactivitymanager().getcurrentactivity(); ca.onactivityresult(requestcode, resultcode, data); } }
as can see, onactivityresult function in parent activitygroup class catch call back, child activity needs jump activity, , transfer data it. may not need onactivityresult function in child activity state in step 2, think better way it.
hope help!
Comments
Post a Comment