Closed Bug 1520754 Opened 6 years ago Closed 6 years ago

Correctly pair events in GleanLifecycleObserver

Categories

(Toolkit :: Telemetry, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
Tracking Status
firefox66 --- affected

People

(Reporter: Dexter, Assigned: travis_)

References

Details

(Whiteboard: [telemetry:mobilesdk:m4])

From Sebastian's comment:

@Dexterp37 You are not using matching/synchronized/paired events here: Either you want to use resume/pause or start/stop here. With the difference being:

* start/stop: App is visible/invisible

* resume/pause: App is in the foreground, the user can interact with it.

An example for an app can going through those methods/state

* User starts the app
  
  * onCreate()
  * onStart()
  * onResume()

* User pulls down the notification shade (-> The app is still visible, but the user is interacting with the notification drawn on top)
  
  * onPause()

* User closes the notifaction shade and is back in the app
  
  * onResume()

* User leaves the app to go to the home screen:
  
  * onPause()
  * onStop()

* User goes back to the app:
  
  * onStart()

* onResume()

* User presses back to close the app:
  
  * onPause()
  * onStop()
  * onDestroy()

See:

* https://developer.android.com/guide/components/activities/activity-lifecycle#onstart

* https://developer.android.com/guide/components/activities/state-changes

Also see: https://developer.android.com/reference/android/app/Activity#ActivityLifecycle

It appears that we're doing it wrong :( We should probably change this line to use ON_START, as far as I understand.

Otherwise, we might overcount metrics updated when entering foreground again.

Blocks: 1491345
Priority: -- → P1
Whiteboard: [telemetry:mobilesdk:m4]

Mike, what's your take on this?

Flags: needinfo?(mdroettboom)

I think this is just from a failure to find the right docs. Obviously, these events should be properly paired. But IIUC, we should use pause/resume, not stop/start if we really want events to be for foreground/background. I also feel it's safest to use the "innermost" pair of events.

I found this image helpful.

Flags: needinfo?(mdroettboom)

Actually, maybe I'm reading this wrong and we do what stop/start...

(In reply to Michael Droettboom [:mdroettboom] from comment #3)

Actually, maybe I'm reading this wrong and we do what stop/start...

From comment 0, it looks to me this should be start/stop, unless we want to send a ping each time the notification shade is interacted with. Moreover, we should really add this to the ping docs: this is a stricter definition of what foreground/background means and it will be very useful for people dealing with the data.

I agree that Start/Stop are the correct lifecycle events to work with here. Especially since a popover or interacting with the notification shade could incorrectly affect recording of metrics.

Assignee: nobody → tlong

Changed to ON_START and updated comment to reflect the issue with using ON_PAUSE/ON_RESUME. Resolved as fixed :)

Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.