Closed jjhesk closed 7 years ago
public void setFragment(F fragment, String title, @Nullable F oldFragment, boolean closeDrawer) {
currentFragmentNow = fragment;
setTitle(title);
if (fragment instanceof NavigationFragment) {
NavigationFragment nav =(NavigationFragment)fragment;
fmstack = SingleStackNavigationManagerFragment.newInstance(nav);
fmstack.setDefaultPresentAnimations(R.anim.popup_show, R.anim.popup_hide);
fmstack.setDefaultDismissAnimations(R.anim.bottom_down, R.anim.bottom_up);
//generate ID for the navigation fragment
mSingleStackNavigationManagerFragmentTag = UUID.randomUUID().toString();
android.support.v4.app.FragmentTransaction fm = getSupportFragmentManager().beginTransaction();
if (currentFragmentNow == null) {
}
currentFragmentNow = fragment;
fm.replace(targetHomeFrame(), fmstack, mSingleStackNavigationManagerFragmentTag);
fm.commit();
}else if (fragment instanceof android.app.Fragment) {
if (oldFragment instanceof android.support.v4.app.Fragment)
throw new RuntimeException("You should use only one type of Fragment");
android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
if (oldFragment != null && fragment != oldFragment)
ft.remove((android.app.Fragment) oldFragment);
ft.replace(targetHomeFrame(), (android.app.Fragment) fragment).commit();
} else if (fragment instanceof android.support.v4.app.Fragment) {
if (oldFragment instanceof android.app.Fragment)
throw new RuntimeException("You should use only one type of Fragment");
android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (oldFragment != null && oldFragment != fragment)
ft.remove((android.support.v4.app.Fragment) oldFragment);
ft.replace(targetHomeFrame(), (android.support.v4.app.Fragment) fragment).commit();
} else
throw new RuntimeException("Fragment must be android.app.Fragment or android.support.v4.app.Fragment");
//if (closeDrawer)
// getSlidingMenu().toggle(true);
notifyOnBodyFragmentChange(currentFragmentNow);
}
This is the final piece that is written. Is it okay to switch between from non-navigation fragment and navigation fragment? #3 ?
i think #3 is not the case because it has been resolved. However these is another bug occurring after this line or sometimes earlier. I am trying to think of any issues from my side that has to deal with nextAnim
.. I am not sure where is it coming from.The only thing that will use the frag manager would the smarttablayout
.. i afraid this is the case that smarttablayout
is crashing heavily with this library.
fixed the issues related the close and open
Can you please elaborate on what the issue was? If it wasn't with the library then this will help others fix the same issue in their project. If it is with the issue I'd like to incorporate any work that you are doing on the library. That way everyone can get the benefits of fixes that you have!
I have re-opened the issue until I know for certain it is not the library code or that it is changed in the library.
Please note all development is taking place on the develop branch. I'd like to keep the master clean as the current live code so that I can manage any hot fixes from there (such as this fix you are talking about and #10)
yes. I will post the code out later. I need to first re-organize my coding block.
basically if there are coding that has been written in the onresume
and onpause
to dealing with the normal fragments that has been initialized in the framelayout
and the crash will incurr as mentioned above. I resolved this crash by removed all those lines that has to do with the normal fragments.
I'm not quite sure the use cases that you are having trouble with normal fragments. Any Fragment that is presented from the NavigationManagerFragment
must be a NavigationFragment
or a NavigationListFragment
. This is what allows the present/dismiss methods to call to the parent NavigationManagerFragment
to remove/add and attach/detach fragments depending on what part of the process you are performing.
Normal fragment can be used to replace/add to the same FrameLayout
as the NavigationManagerFragment
, but NavigationFragments
have no additional functionality without a NavigationManagerFragment
as their parent. All this happens in the background when you call present.
When the NavigationManagerFragment
adds the given fragment to the stack, it is the parent of the fragment and also assigns itself using the setNavigationManager
call when the new NavigationFragment
is presented. This allows the present/dismiss methods to call back to the manager when we need to push/pop a fragment from the stack.
@DMan654 @DMCApps hi there is another issue reappeared again with this.. java.lang.NullPointerException: Attempt to write to field 'int android.support.v4.app.Fragment.mNextAnim' on a null object reference
07-07 12:32:48.027 13206-13206/xxxxxxxx E/AndroidRuntime: FATAL EXCEPTION: main Process:xxxxxxxx , PID: 13206
java.lang.NullPointerException: Attempt to write to field 'int android.support.v4.app.Fragment.mNextAnim' on a null object reference at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1671) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:532) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5422) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I have done some testing on android support v4-24.0.0 BackStackRecord.java line 488.
public FragmentTransaction detach(Fragment fragment) {
Op op = new Op();
op.cmd = OP_DETACH;
op.fragment = fragment;
addOp(op);
return this;
}
This call has triggered 3 times when start an intent activity from another navigation fragment.
The architecture based on starting an AppCompatActivity
A with SingleStackNavigationManagerFragment
and start another AppCompatActivity
B with SingleStackNavigationManagerFragment
from NavigationFragment
. On the activity B we start another fragmentActivity from the one of the NavigationFragment
without SingleStackNavigationManagerFragment
.
3 Attempts from calling detach
version: 0.2.0.3, 0.3.0
The above issue was resolved by taking another fragment lunching in the navigation fragment. Maybe there should be able to get some suggestion from the exception catch.
I'm going to mark this as complete. It looks like there haven't been many occurrences of this reported lately. Please reopen if there is any other instances coming up.
There was a null pointer exception pops out from the system while i compile this library at the start.
which i cannot tell where it was coming from basically it was the last lines of code before it happens.
the issue triggers at
ft.replace(targetHomeFrame(), (android.support.v4.app.Fragment) fragment).commit();
but it was not constantly happening.