Replacing fragments quickly causes a strange screenshot of the previous fragment to be saved and pushed forward

I use the HomeActivity function, which dynamically replaces fragments and dynamically adds it to the content layout as the user selects items from the box. On each fragment, it downloads the feed from the network that it displays. Here is the code I use for the switch -

public void loadFragment(Fragment frag, String tag) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.content_fragment, frag, tag); try { fragmentTransaction.commit(); } catch (IllegalStateException e) { logger.error(TAG, "Failed to commit fragment transaction... ", e); } } 

Now, if I switch between these fragments from the drawer (using DrawerLayout), and I do not allow the network request for each fragment to complete, somehow the replaced new fragment is placed under the screenshot of the old fragment, there was a download. Since the old fragment showed values ​​from the cache, it shows a partial feed.

Split layers using Jake Wharton's scalpel

Now, if you notice that at the top of this stack there is a feed from the new fragment, and it has layers, as it should be, but at the bottom of this stack there is what seems like a screenshot of the previous fragment, and this would seem to be The screenshot / partial draw in the root view is for some reason z-indexed higher than the new one and overshadows it. It also does not interact and is interesting enough, I can scroll through a new channel, which is the z-index below (although this is the highest level in the picture above) even with an overlay.

I tried to traverse the hierarchy of views from the root view and print everything, and I could not find the text of the screen elements (so I believe that its image or some kind of optimization is performed by a third-party library? We also use SwipeToRefresh). I am really confused about what it is and how I can get rid of it. This does not happen if I slowly switch fragments and allow them to load. Any clues?

+1
source share

Source: https://habr.com/ru/post/979424/


All Articles