Link between actions: intention or service: which is faster?

Is there a significant difference in the time required to send data on the service or by intention?

Are there any general tips when to use the service and when to use intentions?

+3
source share
4 answers

These are two completely different things. The question is not what happens faster, but what you are trying to do.

If you want to transfer data from one activity to another, you pass it through intent. If this is not enough for you (too much data, for example), you can use other approaches, but they will not include the Service. For example, you may have a singleton in which your shared data is stored, to which both actions have access ... but be extremely careful that your process is killed at different points, which is why the singleton leaves (and using the service for this will not allow you to leave without dealing with such a situation).

The service should do some work in the background, even if the user does not interact directly with the application. Especially if we talk about things within the same .apk (and, as a rule, one process), there are very few other reasons for using the Service.

+4

, .

, . , startActivityForResult(), .

, /. , Activity, Activity.

. , , , .

+2

. . .

0

, . "" .

, . "" , - - - , . , , . - , , "", . "" Activity.

0

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


All Articles