Android 为什么不可能通过改造循环调用execute以在我的IntentService中获得多个响应?

Android 为什么不可能通过改造循环调用execute以在我的IntentService中获得多个响应?,android,retrofit,intentservice,event-bus,android-priority-jobqueue,Android,Retrofit,Intentservice,Event Bus,Android Priority Jobqueue,为什么不可能通过改造循环调用execute以在我的IntentService中获得多个响应 请查看我的代码: public class UpdateAgendaService extends IntentService { public static final int STATUS_RUNNING = 0; public static final int STATUS_FINISHED = 1; public static final int STATUS_ERROR

为什么不可能通过改造循环调用execute以在我的IntentService中获得多个响应

请查看我的代码:

public class UpdateAgendaService extends IntentService {

    public static final int STATUS_RUNNING = 0;
    public static final int STATUS_FINISHED = 1;
    public static final int STATUS_ERROR = 2;
    private Agenda agenda;
    public UpdateAgendaService() {
        super(UpdateAgendaService.class.getName());
    }

    @Override
    protected void onHandleIntent(Intent intent) {

        final ResultReceiver receiver = intent.getParcelableExtra("receiver");
        String[] dateWeek  = intent.getStringArrayExtra("dateWeek");
        if (dateWeek != null) {
            receiver.send(STATUS_RUNNING, Bundle.EMPTY);

            Bundle bundle = new Bundle();
            try {
                //Why is this not possible?
                List<Agenda> agendaList = getAgendaList(dateWeek); 
                receiver.send(STATUS_FINISHED, bundle);
                }
            } catch (Exception e) {

                /* Sending error message back to activity */
                bundle.putString(Intent.EXTRA_TEXT, e.toString());
                receiver.send(STATUS_ERROR, bundle);
            }
        }
        Log.d(Utilities.TAG, "Service Stopping!");
        this.stopSelf();

    }

    private List<Agenda> getAgendaList(String[] upcomingWeekdates){
        List<Agenda> agendaList = null;
        for (int i = 0; i < upcomingWeekdates.length; i++) {
            String weekDay = upcomingWeekdates[i];
            agendaList.add(getAgenda(weekDay));
        }
        return agendaList;
    }
    private Agenda getAgenda(String date) {
        Agenda agenda = null;
        ApiService apiService = new QardioApi().getApiService();

        Call<Agenda> call = apiService.getAgenda(date);
        try {
            agenda = call.execute().body();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return agenda;

    }
}
公共类UpdateGendaService扩展了IntentService{
公共静态最终int状态_RUNNING=0;
公共静态最终int状态_FINISHED=1;
公共静态最终int状态_错误=2;
私人议程;
公共更新根数据库服务(){
super(UpdateAgendaService.class.getName());
}
@凌驾
受保护的手部内容无效(意图){
最终结果接收方=intent.getParcelableExtra(“接收方”);
String[]dateWeek=intent.getStringArrayExtra(“dateWeek”);
如果(dateWeek!=null){
receiver.send(运行状态,Bundle.EMPTY);
Bundle=新Bundle();
试一试{
//为什么这是不可能的?
List agendaList=getAgendaList(dateWeek);
接收方发送(状态_已完成,捆绑);
}
}捕获(例外e){
/*将错误消息发送回“活动”*/
bundle.putString(Intent.EXTRA_TEXT,例如toString());
接收方发送(状态错误,捆绑);
}
}
Log.d(Utilities.TAG,“服务停止!”);
这个。stopSelf();
}
私有列表getAgendaList(字符串[]upcomingWeekdates){
列表代理列表=null;
对于(int i=0;i
所以情况是,我有一个API,它有一个url:
http//:myapi.com/[date]
,当通过改型调用它时,它会给我一个特定日期议程(事件)的JSON响应。我想做的是显示下一周的议程(事件),这就是为什么我通过给定下一周的字符串日期数组的循环来完成它。想象一下有点像Eventbrite应用程序


我做错了什么?我在某个地方读到,我应该通过JobQueue/Eventbus这样做,我应该这样做吗?但我有点犹豫,因为我不想再使用任何第三方库。然而,如果这是最后一种情况,那么我可能会选择这种情况。

无需担心。那是因为我犯了一个非常愚蠢的错误

我刚刚改变了:

List<Agenda> agendaList = null;
List agendaList=null;

List agendaList=new ArrayList();

别担心,伙计们。那是因为我犯了一个非常愚蠢的错误

我刚刚改变了:

List<Agenda> agendaList = null;
List agendaList=null;

List agendaList=new ArrayList();