android - Navigate back from an Activity to fragment of another Activity -
i have activity(activity1) several fragments. i'm calling second activity(activity2) 1 of fragments(say fragment c) of first activity. want navigate second activity(activity2) fragment c. but, navigating first fragment of activity1 instead of fragment c. please help.
block of code have tried far:
in fragment c,
categorybutton.setonclicklistener(new view.onclicklistener() {
@override public void onclick(view v) { intent i=new intent(getactivity(),activity2.class); getactivity().startactivity(i); } });
in container activity i.e activity1,
fragmenttransaction transaction= getsupportfragmentmanager().begintransaction();
fragmentc myfragment = new fragmentc(); transaction.replace(r.id.frame_container, myfragment); transaction.commit();
according official android documentation best way have fragment communicate another activity through associated activity.
to avoid mess fragment transaction please referring this:
often want 1 fragment communicate another, example change content based on user event. fragment-to-fragment communication done through associated activity. 2 fragments should never communicate directly.
Comments
Post a Comment