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
Evolution of Android Update SystemEvolution of Android Update System
Evolution of Android Update SystemEvolution of Android Update System

By Ivan Kuten

So, how can you update Android on mobile devices? While developing software for Smart TVs and Android-based set-top boxes, we’ve narrowed it down to four ways, discarding some very exotic options:

By ProAndroidDev -
Android News
Happy Railway
Happy Railway

By Hadi Lashkari Ghouchani

This post is on the tail of Railway Oriented Programming in Kotlin by Antony Harfield. So you need to read it first and continue here. As it’s obvious I really liked it and tried it out. It needs every process have a result like

By ProAndroidDev -
Android News
Unit Tests and Concurrency
Unit Tests and Concurrency

By Stojan Anastasov

Once Retrofit added RxJava support, RxJava became my go-to concurrency framework for writing Android apps. One of the great things about RxJava is the excellent testing support. It includes TestObserver, TestScheduler, RxJavaPlugins so you can switch your schedulers in tests.

By ProAndroidDev -
Android News
When Compat libraries will not save you
When Compat libraries will not save you

By Danny Preussler

And why you should avoid using the “NewApi” suppression! The idea of “Compat” libraries was probably one of the key aspects of Android dominating the mobile space. Other than with iOS, Android users often could not update their operating system after a new version launch, simply as their phones won’t allow them to, the Android problem of fragmentation.

 

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