Android: setResult not returning result to Parent Activity -


i have started child activity parent activity using startactivityforresult. after performing required functions in child activity setting result using setresult. not getting result @ parent activity child activity.

heres code.

here how call child activity parent activity.

 intent = new intent(mainactivity.this, child.class);     i.putextra("id", intid);     i.putextra("aid", aid);     i.putextra("mymsg", mymsg);     startactivityforresult(i, 1); 

this how set result child activity.

 @override     public void onbackpressed() {         super.onbackpressed();      intent resultint = new intent();      resultint.putextra("result", "done");      setresult(activity.result_ok, resultint);      finish(); } 

this onactivityresult

   @override protected void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);      if (requestcode == 1) {          if (resultcode == activity.result_ok) {             if(data!=null) {                 toast.maketext(mainactivity.this, "data received", toast.length_short).show();             }         }     }  } 

here when check resultcode==activity.result_ok giving false. , checked intent passed outside of if condition , returning null.

 <activity         android:name=".mainactivity"         android:label="main"         android:parentactivityname=".mainpage"         android:theme="@style/apptheme.noactionbar">         <meta-data             android:name="android.support.parent_activity"             android:value="org.mydomain.mydomain.mainpage" />     </activity>     <activity         android:name=".child"         android:label="child"         android:parentactivityname=".mainactivity"         android:theme="@style/apptheme1">         <meta-data             android:name="android.support.parent_activity"             android:value="org.mydomain.mydomain.mainactivity" />     </activity> 

can me fix issue.

modify onbackpress() method

@override public void onbackpressed() {

 intent resultint = new intent();  resultint.putextra("result", "done");  setresult(activity.result_ok, resultint);  super.onbackpressed();  finish(); 

}

reason: backpress operation performed task before sent result parent activity......


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -