Preferences DataStore in 10min (SharedPreferences deprecated)

  Рет қаралды 72,960

Philipp Lackner

Philipp Lackner

3 жыл бұрын

In this video you will learn to read from and write to preferences datastore in android.
⭐ Get certificates for your future job
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:
pl-coding.com/premium-courses...
💻 Let me personally review your code and provide individual feedback, so it won't backfire and cost you a fortune in future:
elopage.com/s/philipplackner/...
Get the source code for this video here:
github.com/philipplackner/Dat...
Regular Android tutorials on my Instagram: / _philipplackner_
Checkout my GitHub: github.com/philipplackner

Пікірлер: 110
@CoderzF1
@CoderzF1 2 жыл бұрын
This was actually a lot easier to follow than the official CodeLab for DataStore Preferences. They were leading on a goose chase of using repositories
@kommunismusarbeiterjonny
@kommunismusarbeiterjonny 2 жыл бұрын
Yep
@scanskynero3083
@scanskynero3083 11 ай бұрын
truu. I have never wanted to rip my hair out. I stopped halfway because I kinda realized, the guide was intended for people migrating from sharedPreferences
@RRRazzzaRRR
@RRRazzzaRRR 2 жыл бұрын
deprecated: createDataStore() -> NEW: val Context.dataStore by preferencesDataStore(name = "settings") data = dataStore maybe you have some problems with Preferences, you should use it: import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.preferencesDataStore
@gauravthakkar802
@gauravthakkar802 3 жыл бұрын
Really Thankful to you Philip Everyday before I sleep I make sure I see one of your videos Thanks!
@kumarshubham2812
@kumarshubham2812 3 жыл бұрын
plz make a playlist on jetpack architecture components!!!
@Alchemist10241
@Alchemist10241 2 жыл бұрын
In version 1.0.0 (stable version): Instead of: val dataStoreKey = preferencesKey(key) Use the code below in save and read functions: val dataStoreKey = stringPreferencesKey(key)
@haissayf
@haissayf 3 жыл бұрын
I was hoping to find a datastore tutorial by PL. 😊
@vishnusatheesh5633
@vishnusatheesh5633 Жыл бұрын
Thanks man 👍🏻 You're a gem 💎
@soontaek
@soontaek 3 жыл бұрын
Thank you again! This will be very useful for me very soon. And I have some feedback for you :) The way you make your video are pretty good, and I think it would be even better if you include a brief section at the start of the video (maybe after the demo) where you talk about the big steps like an overview. For example: 1. Add dependencies. 2. Create Datastore object. 3. Create function to save data. 4. Create function to read data. 5. Calling the functions from buttons. 6. ... For me this kind of overview helps me follow better because I know where we're at an where we're going next, especially when it's something new. If I have no idea of the big steps I tend to wonder: So are we done with the object creation? Ah not yet. Done yet? Not yet. Is this the last variable that we need? Nope we need one more, no actually one more... (I get distracted like this) This is my personal feedback for you to add to others' feedback and see what suits best for your audience as a whole :) I hope your channel grows even more as days pass, keep up the good work, I'll always support you for the efforts you put in these contents. Thank you!
@Zeeshan-Syed
@Zeeshan-Syed 3 жыл бұрын
Love u man.. U just upload videos exactly what I'm missing or want to learn and without asking you... Your choice of video topic is on point..
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Thank you, what else you want to learn? I'm always open for new ideas. Would be cool if it fits in a 10-20min video
@vidyesh
@vidyesh 3 жыл бұрын
@@PhilippLackner Jetpack compose
@AyushSachan2211
@AyushSachan2211 3 жыл бұрын
@@PhilippLackner a dedicated video on api calls and image processing.
@xD-saleem
@xD-saleem 3 жыл бұрын
@@AyushSachan2211 yes please
@iam-learning6374
@iam-learning6374 3 жыл бұрын
@@PhilippLackner Work Manager
@techmarinar
@techmarinar 2 жыл бұрын
Thanx man this was very helpful 😊
@danyelsh874
@danyelsh874 2 жыл бұрын
you're the best philipp
@ajaydeepak9739
@ajaydeepak9739 3 жыл бұрын
thanks another awesome course
@mehranj73
@mehranj73 3 жыл бұрын
I like these short videos.
@AyushSachan2211
@AyushSachan2211 3 жыл бұрын
+1
@xD-saleem
@xD-saleem 3 жыл бұрын
short videos are more descriptive :)
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Thank you!
@shafaquesattar
@shafaquesattar 3 жыл бұрын
+1
@manishpingale6558
@manishpingale6558 3 жыл бұрын
@@xD-saleem yes +1
@ammarseud5461
@ammarseud5461 3 жыл бұрын
Thanks for the video, useful stuff as always! Also, and I don't want to sound like a smart-ass, but I think we only need to nullify the binding variable in fragments (since only fragments have different lifecycles for their instance and their view, which causes the memory leak in the first place).
@PhilippLackner
@PhilippLackner 3 жыл бұрын
ah you're totally right, I just got used to that since I mostly do my stuff in fragments. Thanks!
@techmarinar
@techmarinar 2 жыл бұрын
Thank you for the valued reminder
@swatiomar8603
@swatiomar8603 3 жыл бұрын
Awesome mentor 🙏
@CoderzF1
@CoderzF1 2 жыл бұрын
Hello, I was a bit confused..... the function createDataStore has been removed as of the Stable release of DataStore.
@maxdev903
@maxdev903 3 жыл бұрын
In version 1.0.0-alpha07 the Context.createDataStore extension function has been removed and replaced with globalDataStore property delegate.
@manusmccolgan9431
@manusmccolgan9431 Жыл бұрын
For anyone wondering that would be: // At the top level of your kotlin file: val Context.dataStore: DataStore by preferencesDataStore(name = "settings")
@kodeHubb
@kodeHubb 3 жыл бұрын
Thanks a lot for this video.
@PhilippLackner
@PhilippLackner 3 жыл бұрын
You are most welcome
@Another0neTime
@Another0neTime 3 жыл бұрын
Another great video!
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Thanks again!
@scanskynero3083
@scanskynero3083 11 ай бұрын
Thanks for this! The official CodeLab was way too complicated for me to follow
@dreamer6228751
@dreamer6228751 3 жыл бұрын
Very interested video!
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Glad you enjoyed it
@KunalGoyal
@KunalGoyal 3 ай бұрын
Please make an updated video on shared preferences for complex tasks
@jcddcjjcdnz
@jcddcjjcdnz 2 жыл бұрын
The old sharedpreferences is deprecated not the androidx version. Don't go down this DataStore track if you are still planning to use the Preferences screens because they are not compatible, no one mentions this. In the docs, sharedpreferences are still recommended for its traditional use case and has the advantage many advantages.
@un-ro
@un-ro 2 жыл бұрын
Well, I am also confused with deprecated statement. There are no even article or something related to migrate preference screen to datastore.
@lucianrekkless418
@lucianrekkless418 3 жыл бұрын
Thanks a lot man! As always very clear and constructed tutorial. Can you also create a video about using dataStore in Java for login session (storing user acount details)?
@leonelp9593
@leonelp9593 Жыл бұрын
im looking for the same
@AlgeriaHere
@AlgeriaHere 3 жыл бұрын
Helpful video , thank you so much , but there is also prototypes , are you making any videos about that ?
@KotlinBek
@KotlinBek 2 жыл бұрын
Hello, Philipp Lacner I got question, if you could answer it that would be very helpful. so, in new API version there would be changes and some codes might be deprecated as you mentioned, but when we are developing new app we must make sure the app should run on older Android versions, so if we use latest technology(code), would it run on older APIs. even though when code deprecated it still works. right? both on older and latest APIs
@heshamabdo6024
@heshamabdo6024 Жыл бұрын
Thank you man
@krishnanath.v922
@krishnanath.v922 3 жыл бұрын
Hey @philip the save and read are async so before reading we should ensure that save is finished right.?
@GrumpyOldMan9
@GrumpyOldMan9 2 жыл бұрын
How do you store objects (like with JSON in SharedPreferences)?
@jam4l
@jam4l 2 жыл бұрын
Thanks for the good video, in a bit large project don't we need to create datastore as a Singltone object ?
@salmaK20012
@salmaK20012 Жыл бұрын
What if we want to read from the data store on a settings screen without providing default values for the switches (I want the switches to be on as soon as the screen comes up, but if I set the stateFlow to lateinit, I will get an error because by the time View model is created, the coroutine hasn't finished executing yet)?
@macheeneraid230
@macheeneraid230 3 жыл бұрын
how about datastore in livedata(viewmodel) i already created my own version though i'm not sure if that is correct.
@vedprakash9099
@vedprakash9099 3 жыл бұрын
Hey in new library I am not able to import preferencesKey with this version implementation "androidx.datastore:datastore-preferences-core:1.0.0-alpha06"
@sudhanshusharma9159
@sudhanshusharma9159 3 жыл бұрын
wow video. Please make video on video streaming and custom view.
@MisterWealth
@MisterWealth 2 жыл бұрын
I want to make a questionnaire styled app. Where there are lets say 5 multiple choice questions. And depending what choice it itll be different prices of something. So like a very basic bare bones version of a shopping cart. Would this be the method to go with? I have a photography business and I want to add up everything at the end and display it to the user.
@mikelantzelo
@mikelantzelo 3 жыл бұрын
Hi and thanks for the great videos you share with us. I have a problem using Datastore.. everything works perfect until trying to open fragment for second time. Then i get error There are multiple DataStores active for the same file: ..... You should either maintain your DataStore as a singleton or confirm that there is no two DataStore's active on the same file (by confirming that the scope is cancelled). Stucked and don't know what to do to fix this... Can you give a little help?
@chiragpatel6410
@chiragpatel6410 3 жыл бұрын
Nice video. I have question how to remove value of the specific key or how to clear whole datastore value like we used to do in shared preference by calling clear()
@KaiqueOcanha
@KaiqueOcanha 2 жыл бұрын
And to remove a spceific key only, use val dataStoreKey = preferencesKey(key) dataStore.edit{ it.remove(dataStoreKey) }
@surflaweb
@surflaweb 2 жыл бұрын
Thanks
@saranyagovindan8423
@saranyagovindan8423 3 жыл бұрын
Hi, do you have any videos for networking and database caching
@javanull262
@javanull262 3 жыл бұрын
Thanks. Please make a video about MVI architecture. Can't find good explanation of that with a simple example :(
@rahulghag4014
@rahulghag4014 3 жыл бұрын
kzfaq.info/get/bejne/btxxhNWYx86aiYE.html
@lokkeshss7024
@lokkeshss7024 3 жыл бұрын
@Philipp Lackner Could we get something on MediaStore API, like how retrieve all photos on an Android device and plug it into a ML Recognition service.
@bboydarknesz
@bboydarknesz 3 жыл бұрын
Wow thanks.. I need help.. I have User model, and want it to save in DataStore with data type as User. So when I read DataStore, I get User data. Any efficient idea how to do it? Thank you
@MonichGPT
@MonichGPT 3 жыл бұрын
How is you update UI from background launch???
@sleepydev4700
@sleepydev4700 3 жыл бұрын
How can I use it in settings fragment?
@Android-gc9nu
@Android-gc9nu 3 жыл бұрын
How to retrieve data from DataStore preference to using in OkHttp Interceptor with Dagger Hilt?
@pradeepkumarreddykondreddy7048
@pradeepkumarreddykondreddy7048 2 жыл бұрын
What is the secure way to store JWT token on android ?
@Sc2MooDy
@Sc2MooDy 3 жыл бұрын
thanks you
@mojeebhasan5283
@mojeebhasan5283 3 жыл бұрын
Dear , My question is reading data from datastore using lifecycleScope is safe. It may causes ANR(Application not responding). Pls make video on how ANR occur on fetching data from datastore
@arcticmax20
@arcticmax20 3 жыл бұрын
Thanks :D
@glory9079
@glory9079 3 жыл бұрын
I listened we can save class of arrayList before Can I !?
@himanshubansal2189
@himanshubansal2189 3 жыл бұрын
dhanyawaad chacha
@akashdeepwadhwa5828
@akashdeepwadhwa5828 2 жыл бұрын
abe angrez hai woh ...lol
@himanshubansal2189
@himanshubansal2189 2 жыл бұрын
@@akashdeepwadhwa5828 pta hai bhai🙂
@rma1563
@rma1563 3 жыл бұрын
Thanks. It was very clear. But can we save Lists/Arrays via Preference DataStore?
@PhilippLackner
@PhilippLackner 3 жыл бұрын
you could, but you better use a database for that
@rezadev5388
@rezadev5388 2 жыл бұрын
hello please make it possible to pay in digital currency to purchase courses.
@johnybaby9574
@johnybaby9574 3 жыл бұрын
wow didn't know sharedpreferences going to be deprecated
@ajaygalagali5963
@ajaygalagali5963 3 жыл бұрын
Thanks :)
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Welcome!
@xD-saleem
@xD-saleem 3 жыл бұрын
still using SharedPreferences :( but since this video is uploaded will switch to dataStore with DI :)
@ProjectAryawarta
@ProjectAryawarta Жыл бұрын
How to secure this?
@danielwaiguru4359
@danielwaiguru4359 3 жыл бұрын
Hey philipp when using a fragment with viewBinding do you really need to set it to null in onDestroy callback?
@prasanthmanimaran5158
@prasanthmanimaran5158 3 жыл бұрын
Yeah it seems. To prevent memory leaks, I believe so.
@haykmkrtchyan7093
@haykmkrtchyan7093 2 жыл бұрын
Actually in activity you don't need to set it to null. This is for fragments.
@prasanthmanimaran5158
@prasanthmanimaran5158 2 жыл бұрын
@@haykmkrtchyan7093 Ahh sorry, I actually meant for fragments too. Didn't realize the "activity" there. Thanks btw 😁
@haykmkrtchyan7093
@haykmkrtchyan7093 2 жыл бұрын
@@prasanthmanimaran5158 Welcome 😁
@danielwaiguru4359
@danielwaiguru4359 2 жыл бұрын
@@haykmkrtchyan7093 yeah sure
@kifkifa56
@kifkifa56 3 жыл бұрын
Good tut , and Friday is not black its white.
@4everdefence
@4everdefence 7 ай бұрын
To anyone watching this video and wishing to add Preferences DataStore to your application. Please note that you should add exception handling before releasing this code into production. The code in this video is not production ready and should be treated accordingly
@codewithpreeti4083
@codewithpreeti4083 3 жыл бұрын
Nice video., I have a question,.how to return a value from lifecyclescope.launch . This value we will get inside this launch and I want to return this in another function.
@PhilippLackner
@PhilippLackner 3 жыл бұрын
use async instead of launch. Then you get the value with .await()
@codewithpreeti4083
@codewithpreeti4083 3 жыл бұрын
@@PhilippLackner okay. Thanks. Any code snippet do you have for this ? It will be helpful. Actually I tried that didn't work..
@MrRahulmalik
@MrRahulmalik 3 жыл бұрын
Shouldn't we specify IO Dispatchers?
@PhilippLackner
@PhilippLackner 3 жыл бұрын
datastore switches to IO dispatcher behind the scenes
@codersaurabh
@codersaurabh Жыл бұрын
its 2023 i dont know sharedpref were deprecated
@BearkFearGamer
@BearkFearGamer 2 жыл бұрын
Way not simple? Complicated Android remaking the road. createDataStore not isn't found for me.
@mehulbisht9708
@mehulbisht9708 3 жыл бұрын
If you think he's clickbaiting by writing "deprecated", don't forget that once he deprecated his channel name as well. 😂😂
@PhilippLackner
@PhilippLackner 3 жыл бұрын
This time it's really deprecated :D
@narendragupta3204
@narendragupta3204 3 жыл бұрын
Hii can u make the video on how to pass data in nested graph in fragments . Let's say Graph1 has fragment A,B,C,D Fragment B contain a graph having fragment P,Q,R,S. So I need to pass model from fragment B to any fragment P,Q,R,S As per needs Plz give me solutions thanks
@magpro8775
@magpro8775 Жыл бұрын
save shared pref to database ? hahahah why i need shared pref if saved user info to database
@antoniokomangyudistira4150
@antoniokomangyudistira4150 3 жыл бұрын
6.6 min with 1.5 time speed 😝
@PhilippLackner
@PhilippLackner 3 жыл бұрын
That's cheating
@VictorFarkas-fp2gl
@VictorFarkas-fp2gl Жыл бұрын
nice smart video 🦥
Should You Use Compose State or StateFlow in Your ViewModels?
13:59
Philipp Lackner
Рет қаралды 71 М.
5 Fatal Coroutine Mistakes Nobody Tells You About
18:15
Philipp Lackner
Рет қаралды 85 М.
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 41 МЛН
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 170 #shorts
00:27
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 49 МЛН
ОСКАР ИСПОРТИЛ ДЖОНИ ЖИЗНЬ 😢 @lenta_com
01:01
DataStore в Jetpack Compose | Android Studio
30:19
Neco Ru
Рет қаралды 6 М.
Everything about storage on Android
12:17
Android Developers
Рет қаралды 18 М.
LiveData deprecated? - Full Guide to StateFlow
17:03
Philipp Lackner
Рет қаралды 53 М.
Full Guide to Jetpack Compose Effect Handlers
24:56
Philipp Lackner
Рет қаралды 87 М.
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 41 МЛН