IntentService源码分析

实现思路

  • thread + handler
  • 暴露唯一接口onHandleIntent给子类实现
  • 消息队列保证任务的顺序性
  • 巧妙的自动退出机制,其关键点
    • stopSelf(int startId), Stop the service if the most recent time it was started was <var>startId</var>.
    • onStartCommand(Intent intent, int flags, int startId), startId is A unique integer representing this specific request to start. Use with {@link #stopSelfResult(int)}.

你可能感兴趣的:(android,IntentService)