This shows you the differences between two versions of the page.
dapm:laboratoare:06 [2018/03/30 10:36] ioana_maria.culic |
dapm:laboratoare:06 [2021/04/20 10:03] (current) ioana_maria.culic [Exercises :] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Laboratorul 06. ===== | + | ===== Lab 07 - Shared Preferences ===== |
====SharedPreferences==== | ====SharedPreferences==== | ||
Line 54: | Line 54: | ||
**Ex2** Create a class named MySharedPreference and add the code below:\\ | **Ex2** Create a class named MySharedPreference and add the code below:\\ | ||
public class MySharedPreference { | public class MySharedPreference { | ||
- | MySharedPreference settings; | + | SharedPreferences settings; |
SharedPreferences.Editor editor; | SharedPreferences.Editor editor; | ||
| | ||
Line 75: | Line 75: | ||
\\ | \\ | ||
TODO: \\ | TODO: \\ | ||
- | - In the constructor, Initializa SharedPreferences.\\ | + | - In the constructor, Initialize SharedPreferences.\\ |
- | - In the save function and put the given String in the editor. Do not forget to commit\\ | + | - In the same function, put the given String in the editor. Do not forget to commit\\ |
- | - In the getValue function take the string from the Shared preferencties and return it\\ | + | - In the getValue function take the string from the Shared Preferences and return it\\ |
- In the clearSharedPreferences function delete all values from preferences | - In the clearSharedPreferences function delete all values from preferences | ||
Line 87: | Line 87: | ||
- When the Go To Second Activity Button is clicked, make an intent and start the next activity(second activity)\\ | - When the Go To Second Activity Button is clicked, make an intent and start the next activity(second activity)\\ | ||
- | **Ex5** In the SecondActivity java class, Initialize the MySharedPreference and set the value of the textview with the String from the sharedPreference. | + | **Ex5** In the SecondActivity java class, Initialize the MySharedPreference and set the value of the textView with the String from the sharedPreference. |
\\ | \\ | ||
RUN THE APP\\ | RUN THE APP\\ | ||
- | **Ex6** Change the default colors of the application. Add Background to the items from the XML file. | + | **Ex6** Change the default colours of the application. Add Background to the items from the XML file.\\ |
- | + | **Ex7** Send a primitive with the intent and show it in the second Activity (putExtra)\\ | |
- | + | ||
- | **BONUS**\\ | + | |
- | **B1** Send a primitive with the intent and show it in the second Activity (putExtra)\\ | + | |
- | **B2** https://www.tutorialspoint.com/android/android_shared_preferences.htm | + |