Loading...
Home
  • Tech Blogs
  • Videos
  • Conferences
    • Droidcon News
    • Upcoming Conferences
    • Become a Partner
    • Past Events
    • Keep Me Informed
    • Diversity Scholarships
  • Community
    • droidcon Team
    • How to Hold a Droidcon
  • Android Careers
Sign In

Global CSS

 

App Startup — Under the hood with Koin library Example

 

 
Hongbeom
Android Developer. 1년차 주니어 안드로이드 개발자입니다.
Published: September 01, 2020
Tweet
Share
 
 

Photo by Fab Lentz on Unsplash

 

App Startup is a part of the library of Android Jetpack. This provides a way to initialize the components needed to start the application. In this article, let’s take the Koin library as an example to learn how the App Startup library works and what benefits it has.

 

Why do you use it? 🧐

We usually use the content providers to initialize the required components when the app starts. However, the content providers is expensive and initialized in an undetermined order. use App Startup, you can initialize the components you need to start the app, define the initialization order explicitly, and provide good performance.

 

How do I use it? 👀

To use this, we need to override two methods. Let’s take a Koin library as an example.

 

 

The Initializer interface defines two methods.

  • create() : Returns the instance, including the operation required to initialize the component.
  • dependencies() : You can control the order of execution by returning a different list of initializers. For example, if you want to run the another initializer after KoinInitializer first, then you can use it as follows!

 

// another initializer classoverride fun dependencies(): MutableList<Class<out Initializer<*>>>{    // initialized after Koin in initialized
    return mutableListOf(KoinInitializer::class.java)
}

 

Now, all you have to do is add a content provider to your AndroidManifestfile.

 

 

If you want to disable single or all automatic initialization or manually initialize components, please review the official document.✨

https://developer.android.com/topic/libraries/app-startup

 

Under the Hood

Let’s take a look at the InitializationProvider class that we wrote first.

 

 

This class inherits ContentProvider and calls the discoverAndInitialize()method of AppInitializer if the context is not null in the onCreate()method. So what is AppInitializer?

 

AppInitializer class

 

We can see that AppInitializer is basically implemented as a Singleton Pattern. Let’s move on to the discoverAndInitialize() method.

 

AppInitializer class

 

The code is a little long, but let’s just look at the important part. First, I’m getting the ComponentName from on line 4 and then the ProviderInfo. And on line 11, if metadata is not null, all keys are imported, and if it is valid information, we saved it in mDiscovered and executed the doInitialize()method.

Then let’s look at the doInitialize() method.

 

 

After checking to see if the component is already initialized on line 10, check to see if it exists in mInitialized on line 18. If it does not exist, take the dependencies list from the component initializer parameters on line 23 and call doInitialize() again if it’s not empty. Then invoke the create()method to initiate the initialization operation.

 

Conclusion

If you have many components that need to be initialized when you start an application, try using App StartUp. I think I can trust and use it because the official version is out.

 

Thanks for reading it!🙌

All codes can be checked here.

 

hongbeomi/HarryPotter

Harry Potter Harry Potter Application is sample based on MVVM architecture. Fetch data from the network via repository…

github.com

 

Reference

  • https://developer.android.com/topic/libraries/app-startup

 

 

 

Tags: Android, Koin, App Startup, AndroidDev, Android App Development

 

View original article at: 


 

Originally published: November 15, 2020

Android News
Compose CameraX on Android
Compose CameraX on Android

By Peng Jiang

Android new UI toolkit Jetpack compose is in beta now, which has all the features you need to build production-ready apps. CameraX is another Jetpack support library, which let you control the camera easier. As compose is still under development, lots of the views are still not available the compose way.

By ProAndroidDev -
Android News
Getting… your BottomSheetScaffold working on Jetpack Compose Beta 03
Getting… your BottomSheetScaffold working on Jetpack Compose Beta 03

By Carlos Mota

It’s Monday, no releases this week, and… there’s a new version of Jetpack Compose — beta 03—available. What a perfect time to just increment 02 to 03 and see what’s new. The API is (almost) final so after updating from alpha to beta there weren’t any big changes to do. However, and remember that’s still in development, there’s always something that I need to update. 

By ProAndroidDev -
Android News
Noisy Code With Kotlin Scopes
Noisy Code With Kotlin Scopes

By Chetan Gupta

Scopes make your code more readable? think again... You are going to encounter these scope functions namely let, run, apply, also, within every Kotlin codebase, along with all the mischievous ways developers exploit their usage from the way they were intended for. Let see how popular opinion on those ends up just as a code noise.

By ProAndroidDev -
Android News
Improving Android DataBinding with Bindables library
Improving Android DataBinding with Bindables library

By Jaewoong Eum

DataBinding is one of the most important factors for MVVM architecture. The basic concept of DataBinding is to link the view and view model via observer patterns, properties, event callbacks, etc. Linking and automating communication between the view via the bound properties or something in the view model has a lot of benefits in the MVVM architecture concept.

By ProAndroidDev -
droidcon News

Tech Showcases,

Developer Resources &

Partners

/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/home-details/EmployerBrandingHeader
EmployerBrandingHeader
https://jobs.droidcon.com/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/jobs-droidcon/jobs.droidcon.com
jobs.droidcon.com

Latest Android Jobs

http://www.kotlinweekly.net/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/kotlin-weekly/Kotlin Weekly
Kotlin Weekly

Your weekly dose of Kotlin

https://proandroiddev.com/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/pad/ProAndroidDev
ProAndroidDev

Android Tech Blogs, Case Studies and Step-by-Step Coding

/detail?content-id=/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Zalando/Zalando
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Zalando/Zalando
Zalando

Meet one of Berlin's top employers

/detail?content-id=/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Academy for App Success/Academy for App Success
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Academy for App Success/Academy for App Success
Academy for App Success

Google Play resources tailored for the global droidcon community

Follow us

Team droidcon

Get in touch with us

Write us an Email

 

 

Quicklinks

> Code of Conduct

> Terms and Conditions

> How to hold a conference

> FAQs

> Imprint

Droidcon is a registered trademark of Mobile Seasons GmbH Copyright © 2020. All rights reserved.

powered by Breakpoint One