Android sharedpreferences tutorial

Android sharedpreferences tutorial

Coding Demos

7 лет назад

50,255 Просмотров

In this tutorial you will about android sharedpreference api and how to use sharedpreference api to store and retrieve a color that later will be used for coloring android toolbar and android statusbar.

Here is how to do it:
- Create 3 android buttons that will each hold a color
- Make those buttons clickable by using Android setOnClickListener
- Define Sharedpreference and make sure the mode is set to private
- Define Sharedpreference.Editor to be able to edit sharedpreference file and store color
- Inside setOnClickListener store the color inside sharedpreference and use the same color for Android toolbar and Android statusbar.
That's it!!

Social media:
▶Twitter: https://twitter.com/codingdemos

Тэги:

#android_sharedpreferences #sharedpreferences #sharedpreferences_android #android_sharedpreferences_example #android_getsharedpreferences #shared_preferences #preferences_android #android_shared_preferences #android_preferences_example #android_getpreferences #getsharedpreferences_android #sharedpreferences_editor #android_app_preferences #android_store_preferences #android_sharedpreferences_tutorial #shared_preference_colors #sharedpreferences_android_tutorial_color
Ссылки и html тэги не поддерживаются


Комментарии:

Faizan Fangari
Faizan Fangari - 22.01.2022 08:42

👍 not know properly English but understood...

Ответить
Highbrow Director
Highbrow Director - 08.03.2020 07:25

Thanks for the video, I learned how to use shared preferences and implemented. Moreover, I learned about Reformating Code from tutorial.

Ответить
Ridwan Satrial
Ridwan Satrial - 02.05.2019 03:39

for Image?

Ответить
Mayur Modi
Mayur Modi - 18.02.2019 12:42

Can you please make another example of shared preference with login activity.

Ответить
OjO Gaming
OjO Gaming - 18.01.2019 20:17

Thanks, it's working. fine but I need more activity so this. how to do please tell me.

Ответить
MA SO
MA SO - 03.12.2018 09:01

Excelente vídeo :) gracias!!

Ответить
shaik appu
shaik appu - 16.11.2018 13:49

what about if i want to set color for entire background not to the toolbar

Ответить
Engineer iOSwala
Engineer iOSwala - 03.09.2018 15:05

Thank you so much Sir well explained the content (y)

Ответить
Rahul Patil
Rahul Patil - 30.07.2018 19:14

requestPermission("android.permission.READ_EXTERNAL_STORAGE"); how solve the error

Ответить
Tejas Patel
Tejas Patel - 21.06.2018 15:33

Yo man .....great work....one thing that i like about you is you are coding very freely and friendly...you never worry what will happen.... you declare and use things just when they needed... you forget to give app name and you done that after the first run... i like it that you forget small small things...because that;s the sign of true programmer......once again ...great job..and very good explanation. :)

Ответить
Tech Bot
Tech Bot - 18.02.2018 22:14

I want to put the shared preferences in a database that only registers settings that work within the app only how would I do this?(also I am using firebase)

Ответить
Vamshi Krishna
Vamshi Krishna - 11.02.2018 16:12

Thank you.

Ответить
KitelJane
KitelJane - 29.01.2018 21:30

Sir can you teach me how to use shared preference on image? Thank you sir

Ответить
nurfaiqah abdul sukor
nurfaiqah abdul sukor - 18.01.2018 05:20

after i save the data . its still ok . but, after i clear cache . it return to default value again . how to solve it ?

Ответить
Riyadh Silva
Riyadh Silva - 19.12.2017 05:50

Thank you, great video!

Ответить
Mohamed Saad
Mohamed Saad - 14.12.2017 18:33

Great explanation !
Thanks a lot

Ответить
Niha Neha
Niha Neha - 06.12.2017 23:59

Thanks a lot! It helped me in clearing my doubts :)

Ответить
Monique Noche
Monique Noche - 21.11.2017 13:33

What about if two Activities will be use? How to pass the value of shared preference to the other? Thank you

Ответить
PriyaRanjan
PriyaRanjan - 09.10.2017 05:28

thank you :) I really like the way you teaches.. :P

Ответить
Samir Designer
Samir Designer - 29.08.2017 16:37

very thanks
like this make for select language by sharedpreference if we use 3 language like en and ar and it
but work for all activity like main activity and about activity and setting
thanks

Ответить
Sad Being
Sad Being - 27.08.2017 13:45

Thanks very much , this was really helpful

Ответить
Manditi Voyager
Manditi Voyager - 25.08.2017 02:32

Great tutorial! By the way, you can use the "Preview" tab on the right. The changes are rendered automatically.

Ответить
The Engine
The Engine - 11.08.2017 02:15

too long, but should only focus on preferences, not GUI, but generally thumbs up!!! thanks for sharing.

Ответить
Travis L
Travis L - 01.08.2017 04:37

Will this backup to google backup cloud?

Ответить
Health And Fitness
Health And Fitness - 25.07.2017 20:51

i am making a button clicking counter app how save click details of button

Ответить
lun L
lun L - 18.07.2017 09:57

may i know how about the button, now i would like to do the colour of button is permanently just like your tutorial, for example, when i click button red, the button red will become red and reopen application, the button still is red while when i click button green, the button green also will become green and same when reopen again, the button green still is green, hope can kindly reply me, very urgent for me, thanks.....

Ответить
Bonni Villaman
Bonni Villaman - 28.05.2017 19:00

Why don't you just declare a method that get the view and depending on the id do something and not repeat the setOnclicklister like 300 times?
Also, why don't you deal with the deprecated items. You can use ContextCompat.getColor(context, R.color.color_name).
Just saying.

Ответить
Roberto Barrero
Roberto Barrero - 14.05.2017 23:57

Thank you, it was very helpful

Ответить
Constanza Paz Vásquez Venegas
Constanza Paz Vásquez Venegas - 10.05.2017 16:58

Thank you for your video! It help me a lot :D
I've a question. What should I do if I want to store the color like drawable, like this : getResources().getDrawable(R.color.colorPrimary)
How can I put it in mEdit if is not an int?

Ответить
fatBoy
fatBoy - 03.05.2017 04:02

hmm this keeps stopping for me...
i guess i'll try it again tomorrow :D

Ответить
Alan Ranjoni
Alan Ranjoni - 29.04.2017 07:51

Thank you!

Ответить
Amit rai
Amit rai - 05.03.2017 20:22

awesome explanation dude ....!! keep it up

Ответить
Alexandre Oliveira
Alexandre Oliveira - 11.01.2017 00:21

Man, your class and your explanation metodoly is amazing...
Tks a lot for share your knowledge.

Ответить