-
Notifications
You must be signed in to change notification settings - Fork 778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2019-04-10:IntentService 的应用场景和使用姿势? #25
Comments
IntentService源码:
使用示例:
|
IntentService是一个存在单独工作线程,onHandleIntent()在工作线程中执行,执行完毕自动销毁的Service, |
|
IntentService的使用:
public class LocalIntentService extends IntentService{
public LocalIntentService(String name) {
super(name);
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
String action = intent.getStringExtra("task_action");
Log.d("IntentService", "receive task :" + action);
SystemClock.sleep(3000); //即使第一个任务休眠,后续的任务也会等待其执行完毕
if("com.example.action.TASK1".equals(action)){
Log.d("IntentService", "handle task :" + action);
}
}
}
Intent service = new Intent(this, LocalIntentService.class);
service.putExtra("tast_action", "com.example.action.TASK1");
startService(service);
service.putExtra("tast_action", "com.example.action.TASK2");
startService(service);
service.putExtra("tast_action", "com.example.action.TASK3");
startService(service); |
没有人描述一下startservice的兼容问题吗 |
1.IntentService 是继承自 Service 并处理异步请求的一个类。 |
|
IntentService 继承于Service |
No description provided.
The text was updated successfully, but these errors were encountered: