D
D
Dmitry2015-01-23 15:26:47
Android
Dmitry, 2015-01-23 15:26:47

What is the most efficient and fastest way to transfer a large amount of data between a service and an activity?

Условие: Имеется сервис, который постоянно получает по сети большие объёмы данных. Часть этих данных необходимо сохранить в базе данных, часть из них необходимо отобразить в activity. Данные, необходимые для отображения, могут обновляться до нескольких раз в секунду. Сервис может существовать и поддерживать соединение без activity.
Имеются различные варианты решения, например:
1. Сервис получает данные, сохраняет в базу данных, уведомляет Activity о появлении новых данных, Activity через ContentProvider получает данные и отображает.
2. The service receives data, sends a Broadcast message with data, which the Activity receives and displays, and saves to the database in parallel. If necessary, the Activity receives data to display through the ContentProvider before receiving broadcast messages.
The problem with the first option is that the database is locked while the data is being written, even when applying various optimizations. It is aggravated by the fact that data can go continuously in large quantities.
What is the best way to pass data for display? What problems can arise in method number 2? Any other options besides those already listed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dzmitry Lukashanets, 2015-01-25
@dmlukas

I think in your case the binding to the service is very good. I will not give links to classes and methods, I think if you are friends with Google, you will find it. I will explain only the general meaning.
Your service is running and you are constantly getting data, some of which is written to the database. When an activity is launched, it is bound to the service, i.e. by and large, this is getting a link to the service in the activity, and having a link to the service in the activity, we can implement anything further, create some kind of callbacks, sign your activation through this link to the service, so that when a new portion of data arrives, it will be displayed on activation. Before the activity is bent to the service and a callback with data is received, they can be pulled through the content provider. There is one caveat to this option, your service and activity must be running in the same process. If the processes are different, then I think a similar option with binding is suitable, only through aidl interfaces, what it is and how it is eaten, I think you will find it on Google.

A
Arthur Glyzin, 2015-02-18
@forceLain

1. The service receives data, writes it to the database through the ContentProvider. The ContentProvider sends a notification to everyone who subscribes to the corresponding Uri when writing data. The Activity has a Loader running that listens for the corresponding Uri and returns data to the Activity each time the ContentProvider has written the data.
2. If everything is spinning in one process, then EventBus

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question