fragmentmanager

IllegalStateException: No activity FragmentManager.java

流过昼夜 提交于 2019-12-11 01:58:06
问题 I was using Eclipse to compile the app, I used to get this error but not a lot. But since I've switch to android studio, I'm getting this crash a lot. Its crashing pretty much every device. I've tried doing everything but can't seem to fix this issue. I've tried using both getfragmentManager() and getSupportFragmentManager(), getting this crash in both. Not sure what to do now? Below is the code I'm using to switch fragments. private void showFragment(Fragment fragment){ fragmentManager =

Back press fragments issue in android

Deadly 提交于 2019-12-11 00:08:42
问题 I have four Fragments: A, B, C, D. Now I am moving from A --> B so my code will be from A to B getActivity().getSupportFragmentManager() .beginTransaction() .replace(R.id.content_frame, new B()) .addToBackStack("A") .commit(); Now from B to C so code will be getActivity().getSupportFragmentManager() .beginTransaction() .replace(R.id.content_frame, new C()) .addToBackStack("B") .commit(); Now from C to D . But I don't want to include C in backstack because on back press I don't want C fragment

getBackStackEntryCount() always returns 0 even after adding addToBackStack and executePendingTransactions()

瘦欲@ 提交于 2019-12-09 14:06:26
问题 I have two activities A and B. Activity A has a mapFragment and I am adding it to backstack. When I come back from to Actvity A from B, I want the fragment to show up in same state as I left it. But getFragmentManager().getBackStackEntryCount() is returning me 0. Here is my code: MapFragment mMapFragment = MapFragment.newInstance(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); mMapFragment.getMapAsync(this); fragmentTransaction.replace(R.id.container,

“commit already called” error in android addToBackStack for fragment

坚强是说给别人听的谎言 提交于 2019-12-08 17:23:34
I had Created a Home activity which includes a Navigation Drawer onclick with fragment. I had included fragmentTransaction.addToBackStack(null).commit(); with the fragment transaction code to go back to previous page. My Desired requirement was NavigationDrawer-->Fragment1-->Fragment2--> On BackButtonPress-->Fragment1(On BackButton Pressed)-->MainActivity. But,Now i am only able to move to Fragment1 ,But cant move to Fragment2 . It shows an error java.lang.IllegalStateException: commit already called In My MainActivity @SuppressWarnings("StatementWithEmptyBody") @Override public boolean

Traversing from fragment to fragment BottomNavigationView icon highlight

别说谁变了你拦得住时间么 提交于 2019-12-08 11:08:19
问题 i am trying to implement a BottomNavigationView, been successful so far. Currently trying to implement the fragment to fragment movement, which is also successful, but somehow when i move from one fragment[radio] to another[stream] the navigationbar is supposed to highlight the icon[stream] but its not happening is there a way i can set the highlight properties through the fragment itself ? Below is the code and snapshot of my application: MainActivity.java import android.support.annotation

“commit already called” error in android addToBackStack for fragment

霸气de小男生 提交于 2019-12-08 07:17:27
问题 I had Created a Home activity which includes a Navigation Drawer onclick with fragment. I had included fragmentTransaction.addToBackStack(null).commit(); with the fragment transaction code to go back to previous page. My Desired requirement was NavigationDrawer-->Fragment1-->Fragment2--> On BackButtonPress-->Fragment1(On BackButton Pressed)-->MainActivity. But,Now i am only able to move to Fragment1 ,But cant move to Fragment2 . It shows an error java.lang.IllegalStateException: commit

No indication as to where NPE could occur

…衆ロ難τιáo~ 提交于 2019-12-08 04:25:53
问题 This is the stack-trace that I get as an error: Process: com.peems.itcrowd, PID: 2949 java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference at android.support.v4.app.FragmentManagerImpl.getFragment(FragmentManager.java:873) at android.support.v4.app.FragmentStatePagerAdapter.restoreState(FragmentStatePagerAdapter.java:215) at android.support.v4.view.ViewPager.onRestoreInstanceState(ViewPager.java:1481) at android.view.View

BackStack Fragments blank on rotation

北城以北 提交于 2019-12-08 03:31:14
问题 In my Activity, I am loading fragments and adding them to the backstack as the user clicks on items. This works fine and the backstack loads well. Unfortunately, when I rotate the device, the activity is blank. I have tried everything possible on SO and on Google. I tried managing the navigation myself by simply replacing the fragments as the user clicks and handling the back as nav. This works fine but I lose the automatic ability which I coded to change the navigation drawer to show the

Replacing fragments in an activity not calling onAttach, onCreate, onCreateView, etc

五迷三道 提交于 2019-12-07 01:12:06
问题 So I have this piece of code here, I am creating a new Fragment and replacing it with another fragment. That works well. However I have notice that on the first line the constructor is being called but the onAttach() , onCreate() etc are not. If I were to uncomment the second line it won't work as updateItem(URL) requires a webView that is initiated in the onCreate() function. DetailViewFragment detailFragment = new DetailViewFragment(); //detailFragment.updateItem(URL); FragmentTransaction

How to keep the same fragment when activity restarts due to orientation change in a Navigation Drawer Activity

筅森魡賤 提交于 2019-12-06 05:51:33
问题 I found many post explaining how get the Fragment from the savedInstanceState Bundle but, because the Activity can swap between 4 Fragments , i need a way to know which Fragment was alive before rotate when the orientation started to change. The reason i have several Fragments is because i am using Navigation Drawer, so each menu item as a fragment. 回答1: I had the same issue and I fixed it adding this to the Navigation Drawer activity code: protected void onCreate(Bundle savedInstanceState) {