Sitemap

Member-only story

Android: Application onCreate overhead

SharedPreferences in credential encrypted storage are not available until after user is unlocked

--

There is a tendency to perform initializations in Application’s onCreate like 3rd party library setup, Ad SDK (especially for apps with multiple activities). While this is fine for a typical app start from launcher (with a corresponding visible window), there are other entry points where this can have a detrimental impact on the app, ranging from performance issues to potential crashes.

Performance

Application’s onCreate can be invoked even without any visible application component like when launching scheduled work and in these cases, there isn’t any need to initialize UI related SDKs like Ads. In worst case, all these initialization tends to increase latency of the launched work, memory usage etc.

Potential Crash

Some of these SDK’s like Google Admob saves data to persistent storage like shared preference and reads them on subsequent initializations/usage. This presents a tricky edge case for apps supporting boot completed broadcast receivers in direct boot mode (directBootAware).

<receiver
android:name=".LockBootReceiver"
android:directBootAware="true"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
</intent-filter>…

--

--

Vairavan Srinivasan
Vairavan Srinivasan

Written by Vairavan Srinivasan

Fitness enthusiast, Sports junkie, Android developer