Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Is above statement true or false?</p> </blockquote> <p>No object "runs" on a thread, anywhere in Java. <em>Methods</em> run on threads.</p> <p>Hence, a more accurate statement is that the lifecycle methods on <code>Service</code> -- <code>onCreate()</code>, <code>onStartCommand()</code>, <code>onBind()</code>, and <code>onDestroy()</code> -- are called on the main application thread.</p> <blockquote> <p>Can someone explain this statement from android reference for Service</p> </blockquote> <p>I don't know how to explain that much better than it is written. While a <code>Service</code> <em>can manage</em> a background thread, a <code>Service</code> is not <em>itself</em> a <code>Thread</code>.</p> <blockquote> <p>If service runs in UI thread then it is not suitable for heavy work</p> </blockquote> <p>No object "runs" on a thread, anywhere in Java. <em>Methods</em> run on threads.</p> <p>Hence, a more accurate statement is that you should not take much time in work directly triggered by the aforementioned lifecycle methods.</p> <blockquote> <p>If there is no activity running then in which thread service will be running?</p> </blockquote> <p>No object "runs" on a thread, anywhere in Java. <em>Methods</em> run on threads.</p> <p>The aforementioned lifecycle methods are called on the main application thread, regardless of whether or not there is an activity in the foreground, or even if an activity exists.</p> <blockquote> <p>Then If I declare Handler in service as well as activity what would happen?</p> </blockquote> <p>You would have an instance of <code>Handler</code>.</p> <blockquote> <p>Because a single Thread has one instance of Handler</p> </blockquote> <p>The default behavior of <code>Handler</code> is to tie itself to the main application thread, no matter whether you create a <code>Handler</code> in an <code>Activity</code> or a <code>Service</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload