سؤال

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]

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top