Data Storage Flashcards

1
Q

What are the four types of data storage for persistent app data?

A

Lightweight variable storage..
Internal and external storage..
Database storage..
Network (cloud) storage..

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

What is lightweight storage?

A

Lightweight storage is a type of low-capacity storage used for data such as user preference. We typically do this using SharedPreferences or its more recent counterpart DataStore, storing them as Key-Value pairs.

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

What is meant by internal/external storage?

A

Data storage from within the file system itself. For example, data stored in a .txt file in the application directory.

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

What is meant by database storage?

A

Data storage using a structured database - either as part of a local file or a locally hosted database server. For example, SQLite or Room are the two primary (local) database options on Android.

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

What is meant by network storage?

A

Network storage means cloud storage, or data storage on an web server. It is perfect for data synchronisation or for backing up data.

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

What scope are SharedPreferences stored in?

A

SharedPreferences has three scopes - activity-level, application-level and system-level.

We can access each one using different methods - getPreferences, getSharedPreferences and getDefaultSharedPreferences respectively.

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

How is data primarily stored in SharedPreferences/DataStore?

A

As a key-value pair <K, V> of primitive data types, such as int, String or float.

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

Recall each SharedPreferences ‘get’ method.

A

Preferences refers to activity level.
SharedPreferences refers to application level.
DefaultSharedPreferences refers to system level.

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

How may we create a SharedPreferences entity?

A

First, get the SharedPreferences object using Activity.getSharedPreferences.

Then, get its Editor object using pref.edit().

Finally, we can put data into it, then commit.

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

What are the main problems with SharedPreferences?

A

It runs on the main thread, so it can block it.

It is not designed for multi-process applications.

There is no transaction support, meaning changes cannot be rolled back.

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

What is DataStore?

A

DataStore is a solution to SharedPreferences’ problems using Kotlin’s coroutines and its ‘Flow’. It includes transactional and thread support, alongside it being type safe.

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

What is the difference between Preferences DataStore and Proto DataStore?

A

Preferences follows the same style as SharedPreferences.

Proto is an alternate approach enforcing type safety using type objects to allow for more complex data that usually can’t fit into key-value pairings.

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

How can we add data to the DataStore?

A

First, get the DataStore object using context.createDataStore. The DS is scoped to whichever context we use.

Then, we can use the .edit object to insert settings that have a key-value pair using dynamic string indexing.

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

What is a ContentProvider?

A

A ContentProvider is an application component designed for data storage and sharing between different applications. It sits between activities and the database, and validates/acquires data on their behalf using queries.

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

What do we need before creating a ContentResolver?

A

We need to specify permissions to allow other apps to use the ContentProvider. We can do this in the manifest file, by defining a <provider></provider> element. Setting android:exported to ‘true’ allows other apps to be able to use it. The client app must first ask permission before using it.

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

How may we query an existing ContentResolver?

A

We must first get the ContentResolver object, then create a content URI. Then, we can pick one of four basic options - insert, query, update or delete.

17
Q

How may we create our own ContentResolver?

A

First, create a class that extends from ContentProvider and define its onCreate, instantiating its db connections. Then we must register it in the manifest file, under <application></application>.

Then, we must define URIs for the content resolver to find the data with, and build a URIMatcher so that our resolver may respond to different types of URI. Then, we can implement our CRUD/getType() methods.

18
Q

What is a URI?

A

A Uniform Resource Identifier identifies resources in our app, in external storage or on the internet.

19
Q

What distinctions must be made when accessing files using a ContentProvider?

A

We can use either file:// or content://.

file:// allows us to access a private file on the system. We may not share these files with other applications.

content:// allows us to access public files on the system. These may be shared with other applications.

20
Q

How must URIs be structured in the Contract class?

A

Each URI must have a base, made up of a scheme - the type - and an authority - like a domain name. e.g. content:// may be our scheme, and com.dancasley.android.todolist may be our authority.

We then need a path, which refers to specific data - e.g. /tasks/ may be our path.

21
Q

What is a URIMatcher?

A

A URI Matcher is a utility class provided by android that allows us to differentiate types of URIs. It takes a URI as an argument, and provides us an integer constant relating to the position of the data we’re trying to find - its R value.

22
Q

What are the purposes of wildcard characters when URI matching?

A

is an integer wildcard, and * is a string wildcard. Placing these after our path tells the URI matcher that we should allow only this type of value at this point in the URI.

Without wildcards, apps could find any type of data they wanted simply by knowing the directory. It’s like a type of firewall.

23
Q

What is the Contract class?

A

The Contract class is a data class stored within an application that stores ‘contracts’, or allowed URIs, that may be received by a ContentProvider in this application.

24
Q

What is the purpose of getType() in a ContentProvider?

A

getType allows us to handle requests for the MIME data type provided by a given URL.

25
Q

How may we define a custom MIME type?

A

We may declare custom MIME types as constants in the Contract class. It must begin with either vnd.android.cursor.item/ for single items, or vnd.android.cursor.dir/ for multiple.