我有一个在启动时执行的活动的异步任务。如果用户手动选择一个位置,那么url包含一个作为asynctask参数传入的值,并且如果用户不指定位置,则异步任务将使用默认url。我的问题是,如果未指定参数,我不能在我的代码上调用url[0]
。有没有办法检查并查看参数是否传递到异步任务?以下是我的尝试。我试过url[0].isEmpty()
和url[0] == null
但都给我IndexOutOfBounds
错误。检查AsyncTask参数是否为空
private class CallDestination extends AsyncTask<String, Void, JSONObject>{
protected JSONObject doInBackground(String...url){
String MYURL = "";
if(url[0].isEmpty()){
MYURL = "http://thevisitapp.com/api/destinations/read?identifiers=10011";
} else{
MYURL = "http://thevisitapp.com/api/destinations/read?identifiers=" + url[0];
}
//TODO make this dynamic as it's passed in from other activity through intent
HttpRequest request = new HttpRequest();
return request.getJSONFromUrl(MYURL);
}