0

Let's say I wan't to do work in the background (off the main thread).

If only one activity needs the result of this background work, is there any difference between starting this off-main-thread work from a service or from an activity? If so, what is the difference?

[Edit 1 start]

Is it something related to component life cycles. An activity might be stopped (and the off-main-thread continues) but then the process might get killed without onDestroy being called. Is onDestroy guaranteed to be called from a service?

[Edit 1 end]

jgreen81
  • 705
  • 1
  • 6
  • 14

1 Answers1

0

None. The different is basically on the lifecycle of the holding object (i.e. Activity or Service), for instance, if you start a Thread on the Activity.onResume() and you move away from that activity (e.g. press home button) before that thread finishes the execution, it will be likely to be holding an instance of a 'dead' activity that could potentially leads to other problems.

Alécio Carvalho
  • 13,481
  • 5
  • 68
  • 74
  • 1
    To add to this, which is a good answer, it will also be influenced by service binding. – zgc7009 May 09 '14 at 18:54
  • This is a good answer. Now, let's say I'm starting the thread in a Service. The problem seems to be post-poned since Android might kill the whole process at any time. Am I right? This is related to one of my other questions: http://stackoverflow.com/questions/23610517/android-state-of-force-killed-applications – jgreen81 May 20 '14 at 15:16