Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
IntentService( String name)
Creates an IntentService.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
IBinder | onBind( Intent intent)
Unless you provide binding for your service, you don't need to implement this method, because the default implementation returns null.
|
||||||||||
void | onCreate()
Called by the system when the service is first created.
|
||||||||||
void | onDestroy()
Called by the system to notify a Service that it is no longer used and is being removed.
|
||||||||||
void | onStart( Intent intent, int startId)
This method is deprecated. Implement onStartCommand(Intent, int, int) instead.
|
||||||||||
int | onStartCommand( Intent intent, int flags, int startId)
You should not override this method for your IntentService.
|
||||||||||
void | setIntentRedelivery(boolean enabled)
Sets intent redelivery preferences.
If enabled is true, If enabled is false (the default),
设置为true时, onStartCommand
返回
START_REDELIVER_INTENT,否则返回
START_NOT_STICKY
关于此的更多内容请参考《 Service简介
》
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
abstract void | onHandleIntent( Intent intent)
This method is invoked on the worker thread with a request to process.
This method is invoked on the worker thread with a request to process. Only one Intent is processed at a time, but the processing happens on a worker thread that runs independently from other application logic. So, if this code takes a long time, it will hold up other requests to the same IntentService, but it will not hold up anything else. When all requests have been handled, the IntentService stops itself, so you should not call
stopSelf()
.
该函数用于针对Intent的不同进行不同的事务处理就可以了.执行完所一个Intent请求对象所对应的工作之后,如果没有新的Intent请求达到,
则自动停止Service;否则
ServiceHandler会取得
下一个Intent请求传人该函数来处理其所对应的任务。
|
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="kwd" style="color: rgb(0, 0, 136);">package</span><span class="pln"> com</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">lenovo</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">robin</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">test</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">app</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">IntentService</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">content</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Intent</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">util</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Log</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div> </div><div><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">class</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">MyIntentService</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">extends</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">IntentService</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">final</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">static</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> TAG</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="str" style="color: rgb(0, 136, 0);">"robin"</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">MyIntentService</span><span class="pun" style="color: rgb(102, 102, 0);">()</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">super</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"com.lenovo.robin.test.MyIntentService"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Log</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">i</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">TAG</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="kwd" style="color: rgb(0, 0, 136);">this</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="str" style="color: rgb(0, 136, 0);">" is constructed"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">@Override</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">protected</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> onHandleIntent</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Intent</span><span class="pln"> arg0</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Log</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">i</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">TAG</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="str" style="color: rgb(0, 136, 0);">"begin onHandleIntent() in "</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="kwd" style="color: rgb(0, 0, 136);">this</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">try</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Thread</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">sleep</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="lit" style="color: rgb(0, 102, 102);">10</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="lit" style="color: rgb(0, 102, 102);">1000</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">catch</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">InterruptedException</span><span class="pln"> e</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> </span><span class="pln"> e</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">printStackTrace</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Log</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">i</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">TAG</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="str" style="color: rgb(0, 136, 0);">"end onHandleIntent() in "</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="kwd" style="color: rgb(0, 0, 136);">this</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> onDestroy</span><span class="pun" style="color: rgb(102, 102, 0);">()</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">super</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">onDestroy</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Log</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">i</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">TAG</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="kwd" style="color: rgb(0, 0, 136);">this</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="str" style="color: rgb(0, 136, 0);">" is destroy"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Intent</span><span class="pln"> intent</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="kwd" style="color: rgb(0, 0, 136);">new</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Intent</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">this</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="typ" style="color: rgb(102, 0, 102);">MyIntentService</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">class</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="pln">startService</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">intent</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="pln">startService</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">intent</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="pln">startService</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">intent</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="tag" style="color: rgb(0, 0, 136);"><service</span><span class="pln"> </span><span class="atn" style="color: rgb(102, 0, 102);">android:name</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="atv" style="color: rgb(0, 136, 0);">".MyIntentService"</span><span class="pln"> </span><span class="tag" style="color: rgb(0, 0, 136);">/></span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="kwd" style="color: rgb(0, 0, 136);">package</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">app</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div> </div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">content</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Intent</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">os</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Handler</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">os</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">HandlerThread</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">os</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">IBinder</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">os</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Looper</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">os</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Message</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div> </div><div><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">abstract</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">class</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">IntentService</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">extends</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Service</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">volatile</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Looper</span><span class="pln"> mServiceLooper</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">volatile</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">ServiceHandler</span><span class="pln"> mServiceHandler</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> mName</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">boolean</span><span class="pln"> mRedelivery</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div> </div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">final</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">class</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">ServiceHandler</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">extends</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Handler</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">ServiceHandler</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Looper</span><span class="pln"> looper</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">super</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">looper</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div> </div><div><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">@Override</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> handleMessage</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Message</span><span class="pln"> msg</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> onHandleIntent</span><span class="pun" style="color: rgb(102, 102, 0);">((</span><span class="typ" style="color: rgb(102, 0, 102);">Intent</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln">msg</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">obj</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> stopSelf</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">msg</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">arg1</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div> </div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">IntentService</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> name</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">super</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln"> mName </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> name</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div> </div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> setIntentRedelivery</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">boolean</span><span class="pln"> enabled</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> mRedelivery </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> enabled</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div> </div><div><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">@Override</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> onCreate</span><span class="pun" style="color: rgb(102, 102, 0);">()</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> </span><span class="com" style="color: rgb(136, 0, 0);">// TODO: It would be nice to have an option to hold a partial wakelock</span></div><div><span class="com" style="color: rgb(136, 0, 0);"> // during processing, and to have a static startService(Context, Intent)</span></div><div><span class="com" style="color: rgb(136, 0, 0);"> // method that would launch the service & hand off a wakelock.</span></div><div> </div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">super</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">onCreate</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">HandlerThread</span><span class="pln"> thread </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">new</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">HandlerThread</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"IntentService["</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="pln"> mName </span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="pln"> </span><span class="str" style="color: rgb(0, 136, 0);">"]"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> thread</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">start</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div> </div><div><span class="pln"> mServiceLooper </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> thread</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getLooper</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln"> mServiceHandler </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">new</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">ServiceHandler</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">mServiceLooper</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div> </div><div><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">@Override</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> onStart</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Intent</span><span class="pln"> intent</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> startId</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Message</span><span class="pln"> msg </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> mServiceHandler</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">obtainMessage</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln"> msg</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">arg1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> startId</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln"> msg</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">obj </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> intent</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln"> mServiceHandler</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">sendMessage</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">msg</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div> </div><div><span class="pln"> </span><span class="com" style="color: rgb(136, 0, 0);">/**</span></div><div><span class="com" style="color: rgb(136, 0, 0);"> * You should not override this method for your IntentService. Instead,</span></div><div><span class="com" style="color: rgb(136, 0, 0);"> * override {@link #onHandleIntent}, which the system calls when the IntentService</span></div><div><span class="com" style="color: rgb(136, 0, 0);"> * receives a start request.</span></div><div><span class="com" style="color: rgb(136, 0, 0);"> * @see android.app.Service#onStartCommand</span></div><div><span class="com" style="color: rgb(136, 0, 0);"> */</span></div><div><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">@Override</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> onStartCommand</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Intent</span><span class="pln"> intent</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> flags</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> startId</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> onStart</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">intent</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> startId</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">return</span><span class="pln"> mRedelivery </span><span class="pun" style="color: rgb(102, 102, 0);">?</span><span class="pln"> START_REDELIVER_INTENT </span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln"> START_NOT_STICKY</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div> </div><div><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">@Override</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> onDestroy</span><span class="pun" style="color: rgb(102, 102, 0);">()</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> mServiceLooper</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">quit</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">@Override</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">IBinder</span><span class="pln"> onBind</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Intent</span><span class="pln"> intent</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">return</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">null</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div> </div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">protected</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">abstract</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> onHandleIntent</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Intent</span><span class="pln"> intent</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>