How to evaluate the effectiveness of ContentProviders in Android?

I have several questions related to the Android platform that I could not find on the Android developer site or elsewhere. So, I am tempted to ask here.

In an interview, they asked me a question:

How do you rate the effectiveness of ContentProviders on Android?

How long will it take if you want to get 3000 contacts? Will it be the same time if you want to receive contact email?

+5
source share
3 answers

First question

How long will it take if you want to get 3000 contacts?

-> Depending on the speed of the device, in any case, the time complexity is linear in input size: O (n)

Second question

Will it be the same time if you want to receive contact email as well?

-> AFAIK Contact emails are located in the data table, in the "Raw contact" section, and each contact can contain more than one email, so maybe you need more time to get all the emails of all contacts compared to only contacts.

Contact Provider - A component of the content provider for Android. It supports three types of person data, each of which corresponds to a table provided by the supplier, as shown in

enter image description here

Read more HERE

+2
source

How do you rate the effectiveness of ContentProviders on Android?

This will be evaluated by the timeout for the request. Thus, you can measure the worst time for the requested request, compare it with your application requirements and see if this can cause a significant wait time for the user.

How long will it take if you want to get 3000 contacts?

Run the code and measure. Will vary on different devices and versions.

Will it be the same time if you also want to receive contact emails?

The types of data and recreation "data" are probably in the same table . Each record is a MIME type data, so an additional record is required for e-mail. A well-formed query can retrieve data from several types at a time, then its cursor processing code to distinguish it.

+1
source

It is just a matter of choosing * from the table. Answer. It’s more efficient to select (columns that you need) from the table.

The best example of senario for reading from a content provider is when the projection contains only the columns that you are going to use and you have a well-coded loop for reading data.

if you pass null for projection, it will take the same amount of time because all columns of the content provider will be returned on both calls.

If on the first call you pass the key_id for projection and the 2nd pass, you pass {key_id, key_email}, the second pass will take longer because the content provider returns more data

Actual time depends on how well you code the loops and what you do with the data in the loop. For example, if in each loop you execute getColumnIndex ("email"), it will take much longer than an optimized program that determines the column indices before entering the loop.

Note that there is no moveToFirst (), it is the fastest read loop for sqllite, the first call to moveToNext () makes moveToFirst () for you.

  if (cursor !=null) { //get column indexes here while (cursor.moveToNext()){ //processing here } } cursor.close()} 
0
source

Source: https://habr.com/ru/post/1208318/


All Articles