Background
I’ve found some tip saying that calling Activity.reportFullyDrawn
might help reducing start up time of apps, and it’s mentioned in some places:
-
https://new.reddit.com/r/androiddev/comments/xk7kq8/improving_app_cold_start_times_with_this_one/
-
https://android-developers.googleblog.com/2021/11/improving-app-startup-facebook-app.html
-
https://developer.android.com/reference/android/app/Activity#reportFullyDrawn()
-
https://medium.com/androiddevelopers/improving-app-startup-with-i-o-prefetching-62fbdb9c9020
Here are some of the things that are written there:
Call reportFullyDrawn() to report TTFD and to let the system know that your activity is finished rendering. To improve app startup, the Android system adjusts optimizations to prioritize work that happens before reportFullyDrawn() is called. Calling this method when your app is in fully usable state will improve your app startup time. Every application should be using this API! And don’t forget to measure it.
Report to the system that your app is now fully drawn, for diagnostic and optimization purposes. The system may adjust optimizations to prioritize work that happens before reportFullyDrawn is called, to improve app startup. Misrepresenting the startup window by calling reportFullyDrawn too late or too early may decrease application and startup performance.
This is also used to help instrument application launch times, so that the app can report when it is fully in a usable state; without this, the only thing the system itself can determine is the point at which the activity’s window is first drawn and displayed. To participate in app launch time measurement, you should always call this method after first launch (when onCreate(android.os.Bundle) is called), at the point where you have entirely drawn your UI and populated with all of the significant data. You can safely call this method any time after first launch as well, in which case it will simply be ignored.
If this method is called before the activity’s window is first drawn and displayed as measured by the system, the reported time here will be shifted to the system measured time.
The problem
I can’t find in any of these, what is the best time to call this function.
What I’ve tried
I tried to look at other apps code, to check here on StackOverflow and ask on reddit. I can only see in the docs that it says you should always call this method after first launch (when onCreate(android.os.Bundle) is called)
.
But at which point there…
I couldn’t find a single sample code that uses it, and there is almost no mention of this function here on StackOverflow. It seems as a small tip to improve something that people usually don’t bother about anyway…
The questions
1.When should I call reportFullyDrawn
?
At the end of each onCreate of an Activity? Or in some callback there, such as the onPreDraw
of this:
val contentView = findViewById<View>(android.R.id.content)
contentView.viewTreeObserver.addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
...
?
Or maybe after setContentView
or within it?
Or something else, such as after splash screen has finished?
2.Does it really improve anything in the app’s experience? Or just for statistics that appear in various websites, such as Play Console and Firebase Analytics? Have you used it too? Noticed any difference?
- Is it just this alone that helps here? Nothing more is needed? If so, why doesn’t Android do it automatically anyway, if it’s such a nice&easy thing to add?