Is above statement true or false?
在Java中的任何地方都没有对象“运行”.方法在线程上运行.
因此,更准确的说法是在主应用程序线程上调用Service – onCreate(),onStartCommand(),onBind()和onDestroy()上的生命周期方法.
Can someone explain this statement from android reference for Service
我不知道怎么解释比写的好多了.虽然服务可以管理后台线程,但服务本身不是线程.
If service runs in UI thread then it is not suitable for heavy work
在Java中的任何地方都没有对象“运行”.方法在线程上运行.
因此,更准确的说法是,您不应该花费太多时间在上述生命周期方法直接触发的工作中.
If there is no activity running then in which thread service will be running?
在Java中的任何地方都没有对象“运行”.方法在线程上运行.
无论前台是否存在活动,或者即使存在活动,也会在主应用程序线程上调用上述生命周期方法.
Then If I declare Handler in service as well as activity what would happen?
你会有一个Handler实例.
Because a single Thread has one instance of Handler
无论您是在活动还是服务中创建处理程序,Handler的默认行为是将自身绑定到主应用程序线程.