dd-sdk-android icon indicating copy to clipboard operation
dd-sdk-android copied to clipboard

Viewpager adjacent fragments have invalid loadingTime

Open Albertoperezs90 opened this issue 2 years ago • 2 comments

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_FRAGMENT flag.
  • Navigate to fragment 2.
  • Check fragment 3 is created but onResume() is not called
  • After a while, navigate to fragment 3 and check onFragmentResumed is triggered and therefore measuring the loadingTime at this point, making it a bigger value than it should be.

Describe what you expected:

  • ViewLoadingTime should 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

Albertoperezs90 avatar Feb 21 '23 17:02 Albertoperezs90

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.

0xnm avatar Feb 23 '23 08:02 0xnm

Thanks @0xnm ! If you need any help, just let me know :)

Albertoperezs90 avatar Feb 23 '23 12:02 Albertoperezs90