I was looking for some help I've spent the last few days trying to pass an ArrayList of Doubles
into another class from an AsyncTask with no success and I am now thinking I should pass the array back to the mainActivity and then run it to the ProxAlert class from there. Is this the way to do it or am I over complicating it? Thanks for your help.
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();
}
I went to transfer it to the main thread but I would have to make it Parcelable and I'm just unsure as the most direct approach. Sorry the error that I get is
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)
Its instantiating before the onCreate(), thats why i was thinking it might be best to passed the array back to the main activity and then to the proxAlert.class