Service on Android?

I created an application that synchronizes with the server. I already have a code that synchronizes when the user clicks a button. Now it's time to add the Service. I have the following questions regarding services for android:

  • will the service be started if the user never starts the application before? (i.e. just installed)
  • when will the service be launched for the first time? can i run it from onCreate main application?
  • If the user clicks the Sync button in the application, should I start this service or should I have another process for it? How can I verify that background synchronization is not happening at the same time?
  • should use ASyncTask even if the service is running as

    startService (new Intent (this, ServiceSync.class));

+4
source share
1 answer

The preferred approach to data synchronization in Android provides a SyncAdapter for synchronization. You have a very good summary of the necessary steps in this post .

You will also find these articles helpful.

Edit:

1-2-3: You can use a related service to manage the interactions and service methods from your business. You have full working samples in the link provided. Basically, you get attached to the service in your onStart activities and untie onStop .

Remember that the service runs in a user interface thread, so each time-consuming task, such as fetching data over a network, must be performed in a separate thread.

4: you don't need AsyncTask .

+2
source

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


All Articles