Kotlin Multiplatform by Tutorials by By Kevin Moore & By Saeed Taheri & By Carlos Mota
Author:By Kevin Moore & By Saeed Taheri & By Carlos Mota
Language: eng
Format: epub
Publisher: Ray Wenderlich
Android
Still in the shared module, open KoinAndroid.kt from androidMain and add this block of code:
actual val platformModule = module { single<Settings> { AndroidSettings(get()) } }
Make sure to import the Settings from com.russhwolf.settings.Settings package.
AndroidSettings is the Android implementation of Settings.
Youâre using Koinâs single keyword, so it provides this dependency as a singleton.
AndroidSettings needs an instance of SharedPreferences in its constructor. Youâre asking Koin to fetch that dependency at runtime. Donât worry! To prevent a crash, youâll provide that dependency soon.
Open OrganizeApp.kt in androidApp module. As you may remember, the initKoin function had a parameter named appModule. Now itâs time to use it.
Pass this block of code to the appModule parameter:
module { //1 single<Context> { this@OrganizeApp } //2 single<SharedPreferences> { get<Context>().getSharedPreferences( "OrganizeApp", Context.MODE_PRIVATE ) } }
Hereâs whatâs going on in the code above:
Setting up SharedPreferences requires an instance of Android Context. Youâre declaring to Koin that it can use the application instance as the singleton context.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Exploring Deepfakes by Bryan Lyon and Matt Tora(7342)
Robo-Advisor with Python by Aki Ranin(7243)
Offensive Shellcode from Scratch by Rishalin Pillay(5914)
Ego Is the Enemy by Ryan Holiday(4882)
Microsoft 365 and SharePoint Online Cookbook by Gaurav Mahajan Sudeep Ghatak Nate Chamberlain Scott Brewster(4626)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4412)
Python for ArcGIS Pro by Silas Toms Bill Parker(3987)
Elevating React Web Development with Gatsby by Samuel Larsen-Disney(3692)
Machine Learning at Scale with H2O by Gregory Keys | David Whiting(3401)
Learning C# by Developing Games with Unity 2021 by Harrison Ferrone(3251)
Speed Up Your Python with Rust by Maxwell Flitton(3213)
Liar's Poker by Michael Lewis(3191)
OPNsense Beginner to Professional by Julio Cesar Bueno de Camargo(3177)
Extreme DAX by Michiel Rozema & Henk Vlootman(3154)
Agile Security Operations by Hinne Hettema(3107)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic and Jasmin Redzepagic(3096)
Essential Cryptography for JavaScript Developers by Alessandro Segala(3067)
Cryptography Algorithms by Massimo Bertaccini(2983)
AI-Powered Commerce by Andy Pandharikar & Frederik Bussler(2968)
