Service实现程序后台运行的解决方案。但如果在服务中做一些耗时操作需要开启子线程。否则会ANR(Application Not Responding)的情况。Android单独提供了了一个类,IntentService。
public class TestIntentService extends IntentService {
public TestIntentService(String name) {
super(name);
}
@Override
protected void onHandleIntent(Intent intent) {
// 在这里做耗时操作
}
}