1

It's 7am and i've been searching all night long on this. I got a Nav drawer and list which dynamically adds fragments to Main activity and switchs to the clicked fragment.

I'm new so let me try be explaing what i tried:

  1. When i first started this project it was fine, now i have black flashs whenever i switch and i can't find any reasons. I thought it was "heavy" work in the onCreate of the fragments, but other than loading views and setting their texts/images there isn't much more work, other than 1 fragment which contains a timer i got 4 others who do nothing but present data.

  2. 1 of the fragments is completely empty in code, and it also flashs.

  3. i had animation in the transaction, but it used to work, not anymore, flashs. i tried removing it but i still get the flashs.
  4. I've read about SurfaceView but it seems too complicated for my project which is just a simple time&money tracker.

important notes: when i click the Back button there's no flash and the animation runs smoothly. I'm testing on my own device which is Galaxy s5.

What i've read so far that didn't help: Whole screen turns into black for a short while when first switching between Fragment and MapFragment

Starting activity shows black flash

Switching between Android Navigation Drawer image and Up caret when using fragments

https://code.google.com/p/gmaps-api-issues/issues/detail?id=4639

**

  • EDIT

** I think i have a lead: The flickering could be caused by the closeDrawer i have called right after i commit a new fragment. when the drawer is open, the ui behind it is dimmed, i disabled that close call and when i change fragments no flickering.

i don't know how to fix it tho.

Community
  • 1
  • 1
Shaul
  • 211
  • 1
  • 4
  • 18

1 Answers1

1

After last edit i got a better description of the problem and found a good solution(at least for me) link: DrawerLayout's item click - When is the right time to replace fragment?

private class DrawerItemClickListener implements OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
    drawerLayout.closeDrawer(drawerList);
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            switchFragments(position); // your fragment transactions go here
        }
    }, 200);
}

}

Community
  • 1
  • 1
Shaul
  • 211
  • 1
  • 4
  • 18