我一直在寻找一些帮助,过去几天我一直在尝试将ArrayList of Doubles
AsyncTask 中的一个传递给另一个类,但没有成功,我现在想我应该将数组传递回 mainActivity,然后将其运行到 ProxAlert 类那里。这是这样做的方法还是我把它复杂化了?谢谢你的帮助。
try{
ArrayList<LatLonPair> nPosition = new ArrayList<LatLonPair>();
JSONArray jArray = new JSONArray(result);
System.out.println("Length"+ jArray.length());
Log.d("DB","Length"+jArray.length());
for(int i=0; i<jArray.length(); i++){
JSONObject json_data = null;
json_data = jArray.getJSONObject(i);
int eventID = i +1;
String title = json_data.getString("Title");
double latitude = json_data.getDouble("Lat");
double longitude = json_data.getDouble("Lon");
LatLonPair p = new LatLonPair(latitude , longitude);
nPosition.add(p);
//System.out.println(eventID+"&"+latitude+"&"+longitude);
System.out.println("this" + p.printPoints());
}
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
Log.e("log_tag","Failed data as:\n"+result);
}
return nPosition;
}
@Override
protected void onPostExecute(ArrayList<LatLonPair> result) {
new ProxAlert().registerIntents(result);
super.onPostExecute(result);
//Intent i = new Intent();
//i.putParcelableArrayListExtra("nPositon",(ArrayList<LatLonPair>) result);
//startARActivity();
}
我去把它转移到主线程,但我必须让它 Parcelable ,我只是不确定是否是最直接的方法。抱歉,我得到的错误是
09-18 12:27:16.605: E/AndroidRuntime(20122): java.lang.IllegalStateException: System services not available to Activities before onCreate()
09-18 12:27:16.605: E/AndroidRuntime(20122): at android.app.Activity.getSystemService(Activity.java:3562)
09-18 12:27:16.605: E/AndroidRuntime(20122): at com.example.test.ProxAlert.setProximityAlert(ProxAlert.java:51)
09-18 12:27:16.605: E/AndroidRuntime(20122): at com.example.test.ProxAlert.registerIntents(ProxAlert.java:37)
09-18 12:27:16.605: E/AndroidRuntime(20122): at com.example.test.retrieveDB.onPostExecute(retrieveDB.java:116)
09-18 12:27:16.605: E/AndroidRuntime(20122): at com.example.test.retrieveDB.onPostExecute(retrieveDB.java:1)
09-18 12:27:16.605: E/AndroidRuntime(20122): at android.os.AsyncTask.finish(AsyncTask.java:417)
09-18 12:27:16.605: E/AndroidRuntime(20122): at android.os.AsyncTask.access$300(AsyncTask.java:127)
09-18 12:27:16.605: E/AndroidRuntime(20122): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
它在 onCreate() 之前实例化,这就是为什么我认为最好将数组传递回主要活动,然后传递给 proxAlert.class