Data Storage Flashcards

1
Q

What are the 6 data storage options on android? Define each…

A

Shared Preference -> Structure that contains key-value pairs of primitive types.
Internal Storage -> Small, on device storage.
External Storage -> External storage for larger memory.
SQLite -> Lightweight relational database.
Files -> Store data on files.
Cloud -> E.g Google Cloud or Azure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of Cache Files? How do we get the cache directory?

A

Store temporary, non-persistent files.
Obtain through the getCacheDir( ) method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What library is Shared Preferences in?

A

Android.content.SharedPreference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 3 things Shared Preference are mainly used to store?

A

State information
Preferences
Shared Data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What type of file is Shared Preferences stored in?

A

XML

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between Shared Preference and Saved Instance State.

A

Shared Preference -> Saves data across sessions, persistent data, stores user preferences.
savedInstanceState -> Focuses on reconstruction of the UI after rotation.
Both store small and private data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the 3 levels of Preferences?

A

Activity.getPresferences( ) -> Activity wide.
Activity.getSharedPreferences( ) -> Application wide.
PreferenceManager.getDefaultySharedPreferences( ) -> System wide.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of a preference fragment?

A

Creates a hierarchy of preference objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Give a brief definition of what a Shared Preference is…

A

A Shared Preference is a bundle of key-value pairs that store persistent app data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the 5 main uses of Shared Preference?

A

Login information -> E.g email, password, username.
User Actions -> E.g Store previous queries.
Cache data -> Improves app efficiency.
Persisting Application State -> E.g if something has been completed by the user.
User Preferences -> E.g font size, theme.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When and why is getSharedPreferences( ) called? Explain it’s parameters…

A

To create the initial SharedPreference instance, or return the existing one.
Argument 1 -> The name of the SharedPreference.
Argument 2 -> The mode of the Shared Preference. This determines the preferences accessibility from other apps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the 5 steps for using Shared Preferences?

A

1) Get the SharedPreference instance.
2) Get the editor for the SharedPreference instance.
3) Put values into the preference (primitive types).
4) Commit the changes to the preference instance.
5) Get values from the Shared Preference.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When getting values from the SharedPreference, what are the arguments of the Get method?

A

Argument 1 -> Key value
Argument 2 -> Default value if the key is not found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a Preference Fragment?

A

A UI component that displays a heirarchy of preferences that the user can interact with.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When is a Preference Fragment mainly used?

A

In an Activity in which the user can interact with the UI to change persistent attributes of the app. For example, a Settings activity, in which user changes are saved to the Shared Preference.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Where does a Preference Fragment save to?

A

Shared Preferences.

17
Q

What class does a Preference Fragment extend?

A

Fragment.

18
Q

What are the 3 steps to implementing a Preference Fragment?

A

1) Create a class that extends PreferenceFragment.
2) Define an XML for the Preference Fragment.
3) Inflate the XML and add to the activity.