java - Android - Fragment 2 Displaying back the main fragment with Activity -
from main fragment opened videoplayerfragment, in videoplayerfragment when press button should go parent fragment.
collectiondemoactivity{ class launchpadsectionfragment extends listfragments{ public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); string fragmaingroups = "maingroups"; fragment fragment1 = new videoplayerfragment(); fragmenttransaction transaction = getchildfragmentmanager().begintransaction(); transaction.replace(r.id.contentfragment, fragment1, fragmaingroups ); transaction.addtobackstack(fragmaingroups); transaction.commit(); } } }
external class
videoplayerfragment.java
class videoplayerfragment extends listfragment{
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { string groups = "groups"; fragment fragment1 = new collectiondemoactivity.launchpadsectionfragment(); fragmenttransaction transaction = getchildfragmentmanager().begintransaction(); transaction.replace(r.layout.load_main_groups_activty, fragment1, groups); transaction.addtobackstack(groups); transaction.commit(); }
}
i have use code below open previous fragment backstack using fragment tag.
string fragmaingroups = "maingroups"; string groups = "groups"; fragment fragment = (fragment) getfragmentmanager().findfragmentbytag(fragmaingroups); if (fragment != null) // null if not instantiated yet { if (fragment.getview() != null) { // pop backstack on childmanager if there any. if not, close activity normal. if (!fragment.getfragmentmanager().popbackstackimmediate()) { fragment.getfragmentmanager().popbackstack(); //getactivity().finish(); } } }
Comments
Post a Comment