Good Practices Fragment e Service

0

Then the question is personal and the following ..

I have an activity connected to a service.

I want to start a fragment and this fragment will execute functions inside the service.

What would be the best practices to perform functions in the service? Any examples?

    
asked by anonymous 25.07.2014 / 00:19

1 answer

1

There are several points to weigh.

@Piovezan is not bad, it depends on what needs to be done.

If you need to perform functions independently of the Activity, create the service without bind, so even with the application closed the service will continue to run.

Now if you really need to switch information from the activity to the service it needs to be bind and do not add a snippet to it just pass on the information.

  • Bind is not mandatory but guarantees that at the end of the activity the service will also stop, in case of dependency it avoids errors.

The problem of using Broadcasts is the runtime that should be up to 10 seconds to not crash the application, so it is not feasible to do this unless from the receipt you create an AsyncTask or make sure that the execution will not go away!

    
25.07.2014 / 03:16