android - onActivityResult not being called after FragmentActivity -
android - onActivityResult not being called after FragmentActivity -
i have activity calls activity b (fragmentactivity) using startactivityforresult()
. before activity b finishes calling finish()
, utilize setresult()
. in spite of of this, onactivityresult()
not called. i'm not sure i'm doing wrong i'm not doing unconventional, or if android bug.
seeing of suggestions on here, i've checked see don't have android:launchmode="singleinstance"
nor android:nohistory="true"
set anywhere in manifest file.
calling activity b a:
intent intent = new intent(getactivity(), activityb.class); startactivityforresult(intent, my_result);
finishing activity b:
intent intent = new intent(); setresult(activity.result_ok, intent); finish();
overriding onactivityresult()
in activity a:
@override public void onactivityresult(int requestcode, int resultcode, intent data){ toast.maketext(getapplication(), "toast", toast.length_long).show(); }
edit 1
i commented out of activity b's code (see below), leaving a's intact , problem remained. so, doing unusual causes problem. worse, have done other activities (using same code) without problems! extends expandablelistactivity
, although don't understand how of code cause issues in onactivityresult()
. logcat isn't giving me useful.
this code tested activity b, posterity's sake (though seems problem in a):
public class activityb extends fragmentactivity{ @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.layout_activityb); intent intent = new intent(); intent.putextra("data", "hello activityb"); setresult(activity.result_ok, intent); finish(); } }
try , verify code:
activitya.java
public class activitya extends activity{ private static final int my_result = 0; private button btnstart; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_a); btnstart=(button)findviewbyid(r.id.btnstart); btnstart.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { intent intent = new intent(this, activityb.class); startactivityforresult(intent, my_result); } }); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); toast.maketext(getapplication(), data.getstringextra("data"), toast.length_long).show(); } }
activityb.java
public class activityb extends fragmentactivity{ protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_b); intent intent = new intent(); intent.putextra("data", "hello activityb"); setresult(activity.result_ok, intent); finish(); } }
note : create sure have added both activity in manifest file.
android
Comments
Post a Comment