6

When I use the Downloadable Fonts feature on Android, I can add a preloading strategy by adding this code to AndroidManifest.xml:

<meta-data android:name="preloaded_fonts" 
           android:resource="@array/preloaded_fonts" />

When exactly is this loaded? On app startup? On installation? If it's on app startup, and I am using the font on the very first screen, is there any performance difference at all?

Florian Walther
  • 6,237
  • 5
  • 46
  • 104
  • 1
    I have exactly this issue now. The downloadable font on the first screen takes a split second too long. It show roboto font and half a second later it swaps to the specified font. Even **WITH** the preloading strategy.. Any ideas on that? – Tobi Nov 28 '20 at 10:21
  • As far as I remember I couldn't see any effect at all from "preloading" fonts – Florian Walther Nov 28 '20 at 14:30
  • So any suggestions how to handle this properly? – Tobi Nov 28 '20 at 20:44
  • @Tobi You can use XML fonts, they're bundled with the APK and won't cause a delay (but a larger APK size) – Florian Walther Nov 28 '20 at 21:28

1 Answers1

1

https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts#predeclaring-fonts

Layout inflation and resource retrieval are synchronous tasks. By default, the first attempt to retrieve fonts triggers a request to the font provider, and therefore increases the first layout time. To avoid the delay, you can pre-declare fonts that need retrieving in your manifest. After the system retrieves the font from the provider, it is available immediately. If the font retrieval takes longer than expected, the system aborts the fetching process and uses the default font.

norbDEV
  • 4,795
  • 2
  • 37
  • 28
  • 1
    That doesn't say when the loading happens – Florian Walther Sep 15 '20 at 10:36
  • From the top diagram of the site I think the font downloaded async when you download the app. Then the font cached. If another app uses the same font the app uses it from the cache. If the app small enough and starts before the font download finished then the default font will be used, and the next app start the custom font will be. – norbDEV Sep 15 '20 at 11:51