Fixed
Status Update
Comments
il...@google.com <il...@google.com>
th...@outlook.com <th...@outlook.com> #2
Thank you for reporting this issue. For us to further investigate this issue, please provide the following additional information:
Steps to reproduce
Please provide source code or apk of a sample application to reproduce the issue.
Also kindly mention the steps to be followed for reproducing the issue with the given sample application.
Expected output
What is the expected output?
Current output
What is the current output?
Steps to reproduce
Please provide source code or apk of a sample application to reproduce the issue.
Also kindly mention the steps to be followed for reproducing the issue with the given sample application.
Expected output
What is the expected output?
Current output
What is the current output?
il...@google.com <il...@google.com> #3
Seeing this with a FragmentPagerAdapter as well. Our app has three static tabs, and opens by default on tab 1. Previously, the fragments for tab 2 and tab 3 would have their onResume() called when the activity's onResume() was called, even though those tabs weren't visible yet.
Now, since 27.1.0, onResume() on those tabs' fragments is only called when the user navigates to them.
Now, since 27.1.0, onResume() on those tabs' fragments is only called when the user navigates to them.
ap...@google.com <ap...@google.com> #4
#3 can you try to provide a repro app? I've lost 4 hours already and can't find the root cause, the basic AS sample does not produce that :(
Maybe it's easier from your code.
Maybe it's easier from your code.
cl...@google.com <cl...@google.com> #5
I also tried with the sample app (https://github.com/googlesamples/android-HorizontalPaging ) which doesn't have the issue.
I did find a clue in my app though: the first tab's fragment does getLoaderManager().initLoader() in its onActivityCreated(). If I comment this out, the onResume() methods of all the fragments are called at once as with support lib 27.0.2.
This might be related to this change in the support lib release notes:
> The underlying implementation of Loaders has been rewritten to use Lifecycle.
It's going to be quite a bit of work to get this into a small sample app though. I can't share my own app.
I did find a clue in my app though: the first tab's fragment does getLoaderManager().initLoader() in its onActivityCreated(). If I comment this out, the onResume() methods of all the fragments are called at once as with support lib 27.0.2.
This might be related to this change in the support lib release notes:
> The underlying implementation of Loaders has been rewritten to use Lifecycle.
It's going to be quite a bit of work to get this into a small sample app though. I can't share my own app.
na...@google.com <na...@google.com> #6
Thanks I can also confirm the same thing in my case.
Removing the call to getLoaderManager().restartLoader(id, null, this); from onResume of the fragment then allows proper resuming of all fragments. (In my case all loaders Id are different).
This give a clue at how to reproduce, will see if I can tonight.
Removing the call to getLoaderManager().restartLoader(id, null, this); from onResume of the fragment then allows proper resuming of all fragments. (In my case all loaders Id are different).
This give a clue at how to reproduce, will see if I can tonight.
th...@outlook.com <th...@outlook.com> #7
A sample app is here: https://github.com/calvarez-ov/android-HorizontalPaging
If you build it as-is, you see three onResume() logs at once, when the app is launched:
02-28 14:03:43.534 15309 15309 V MainActivity/DummySectionFragment: onResume 1
02-28 14:03:43.682 15309 15309 V MainActivity/DummySectionFragment: onResume 2
02-28 14:03:43.682 15309 15309 V MainActivity/DummySectionFragment: onResume 3
If you change it to use support library 27.1.0 (Application/build.gradle), you only see the first onResume(). You see the other ones after you manually click on the tabs:
02-28 14:07:15.491 15443 15443 V MainActivity/DummySectionFragment: onResume 1
...
02-28 14:07:21.504 15443 15443 V MainActivity/DummySectionFragment: onResume 3
...
02-28 14:07:25.119 15443 15443 V MainActivity/DummySectionFragment: onResume 2
Note, this sample app doesn't look anything like the real app which has the same problem :) It's just the smallest example I could make to reproduce the issue. There's no ListView or RecyclerView and no adapter to display the loader data. I explicitly call forceLoad() to make the loader's loadInBackground() be called. If I don't do this, I have the bug even with support lib 27.0.2.
If you build it as-is, you see three onResume() logs at once, when the app is launched:
02-28 14:03:43.534 15309 15309 V MainActivity/DummySectionFragment: onResume 1
02-28 14:03:43.682 15309 15309 V MainActivity/DummySectionFragment: onResume 2
02-28 14:03:43.682 15309 15309 V MainActivity/DummySectionFragment: onResume 3
If you change it to use support library 27.1.0 (Application/build.gradle), you only see the first onResume(). You see the other ones after you manually click on the tabs:
02-28 14:07:15.491 15443 15443 V MainActivity/DummySectionFragment: onResume 1
...
02-28 14:07:21.504 15443 15443 V MainActivity/DummySectionFragment: onResume 3
...
02-28 14:07:25.119 15443 15443 V MainActivity/DummySectionFragment: onResume 2
Note, this sample app doesn't look anything like the real app which has the same problem :) It's just the smallest example I could make to reproduce the issue. There's no ListView or RecyclerView and no adapter to display the loader data. I explicitly call forceLoad() to make the loader's loadInBackground() be called. If I don't do this, I have the bug even with support lib 27.0.2.
na...@google.com <na...@google.com> #8
In case this helps troubleshooting: if you post the restartLoader() (or initLoader()) call to a Handler, the bug goes away:
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
- getLoaderManager().restartLoader(1337, null, this);
+ new Handler().post(new Runnable() {
+ @Override
+ public void run() {
+ getLoaderManager().restartLoader(1337, null, FragmentWithLoader.this);
+ }
+ });
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
- getLoaderManager().restartLoader(1337, null, this);
+ new Handler().post(new Runnable() {
+ @Override
+ public void run() {
+ getLoaderManager().restartLoader(1337, null, FragmentWithLoader.this);
+ }
+ });
}
Description
Version used: 2.6.0-alpha05 and up (including 2.6.0 stable)
Devices/Android versions reproduced on: Any
In the sample project I try to determine if the home fragment is visible using NavController.visibleEntries. In library version alpha04 it always contains the correct entries, but in alpha05 the list is a hot mess because it keeps growing when navigating and even the host fragment and fragments that are not on the backstack are added to the list. This is not possible in the sample project.
The sample project logs the information for demonstration.