Viewpager adjacent fragments have invalid loadingTime
Describe what happened
Fragments loaded by viewpager are created when visiting adjacents fragments but if you specify the flag BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT onResume() is not triggered until the fragment is actually visible to the user.
The above behavior is triggering viewLoadingTimer.onCreated() on all the adjacents fragments created, but because onResume() is not called until fragment is visible, the loadingTime is invalid giving bigger values than the real loadingTime.
Steps to reproduce the issue:
- Create a viewpager and introduce 4 fragments
- Set an adapter on viewpager with
BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENTflag. - Navigate to fragment 2.
- Check fragment 3 is created but
onResume()is not called - After a while, navigate to fragment 3 and check
onFragmentResumedis triggered and therefore measuring the loadingTime at this point, making it a bigger value than it should be.
Describe what you expected:
-
ViewLoadingTimeshould be stopped temporally if fragments belong to viewpager and are not visible to the user.
Additional context
- Datadog SDK version:
com.datadoghq:dd-sdk-android:1.14.0 - Gradle Plugins:
com.datadoghq:dd-sdk-android-gradle-plugin:1.5.1
Hello @Albertoperezs90. Thanks for opening the issue. Indeed, loading time reporting may be not correct because of the delayed lifecycle calls as you've described.
We will try to look at this and see how we can improve reporting.
Thanks @0xnm ! If you need any help, just let me know :)