This might be a simple question, but I just can't figure it out. Consider the code below:
private void getJSONData() {
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://dev.vision-is.nl/klanten/so/content.json", new AsyncHttpResponseHandler() {
#Override
public void onSuccess(String response) {
// TODO Auto-generated method stub
try {
JSONArray jsonArray = new JSONArray(response);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String titleString = (String) jsonObject.get("title");
titleArray = new ArrayList<String>();
titleArray.add(titleString);
System.out.println(titleArray.get(0));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#Override
public void onFailure(Throwable arg0, String arg1) {
// TODO Auto-generated method stub
System.out.println(arg1);
}
});
}
This code works and gives me the output:
01-20 13:11:48.076 31508-31508/com.soccer.soccerapp I/System.out﹕ OUTPUT: Barcelona - Real Madrid
01-20 13:11:48.076 31508-31508/com.soccer.soccerapp I/System.out﹕ OUTPUT: Ajax - Barcelona
01-20 13:11:48.077 31508-31508/com.soccer.soccerapp I/System.out﹕ OUTPUT: Manchester United - Chelsea
01-20 13:11:48.078 31508-31508/com.soccer.soccerapp I/System.out﹕ OUTPUT: Ajax - PSV
Here comes the problem! When I try to retrieve the array in the "onCreate void" the app will crash...
Code:
public class ActivitiesViewController extends Activity {
ArrayList<String> titleArray;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitiesviewcontroller);
getJSONData();
System.out.println(titleArray.get(0));
}
}
What is wrong with the code? I retrieve the json data. Store this data in an array and when I try to retrieve this data the app will crash.
Change your getJSONData() method like this
private ArrayList<String>() getJSONData() {
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://dev.vision-is.nl/klanten/so/content.json", new AsyncHttpResponseHandler() {
#Override
public void onSuccess(String response) {
// TODO Auto-generated method stub
try {
JSONArray jsonArray = new JSONArray(response);
titleArray = new ArrayList<String>();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String titleString = (String) jsonObject.get("title");
titleArray.add(titleString);
System.out.println(titleArray.get(0));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#Override
public void onFailure(Throwable arg0, String arg1) {
// TODO Auto-generated method stub
System.out.println(arg1);
}
});
return titleArray;
}
then your activity oncreate code should be
public class ActivitiesViewController extends Activity {
ArrayList<String> titleArray;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitiesviewcontroller);
titleArray = getJSONData();
System.out.println(titleArray.get(0));
}
}
Since you're using an AsyncHttpClient the code to execute the network request will not execute parallel to the rest of your code.
Let's take a look at your code:
getJSONData();
System.out.println(titleArray.get(0));
This way, getJSONData() will execute, as will the System.out.println(). But the println() will (probably) give an IndexOutOfBoundsException since titleArray is still empty.
Why is it empty? The AsyncHttpClient will load the data in the background, so your ArrayList will get its content in the onSuccess of the AsyncHttpResponseHandler after the request succeeded and not right after you started the task to download your data. Calling get() will start a procedure that will not prevent the rest of your code to execute, thus the println is reading an empty array.
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://dev.vision-is.nl/klanten/so/content.json", new AsyncHttpResponseHandler() {
#Override
public void onSuccess(String response) {
// Process data after request succeeded
}
#Override
public void onFailure(Throwable arg0, String arg1) {
// Print error after request failed
}
});
The pattern of asynchronous methods is the way we prevent our apps from freezing or crashing, which (of course) irritates our users.
You should execute your task and then process all data whenonSuccess is called by the AsyncHttpClient to confirm that the information you asked for was successfully received. Just don't try to access data of which you're not sure you already have.
You might want to take a look here: http://developer.android.com/guide/components/processes-and-threads.html
Since you using AsyncHttpClient client = new AsyncHttpClient();.
So it is Executing the Next Statement in Asyn Manner.
i.e:It is Executing the Next statement in Parallel with Previous way
getJSONData();
System.out.println(titleArray.get(0));
Change the return of getJSONData() to ArrayList<String> from void
Now if you try to get the value at different position you can find it
Hope this could help ...
Related
My defined function returns a JSONObejct Arraylist, however, when I instantiate a new Arraylist to the output of the function, it shows an empty Arraylist. How can I fix this issue and why is it showing an empty array list when it is indeed returning an Arraylist in the function?
Here is the code :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activty_departures);
departure_flights = doGetRequest();
}
//my function
private ArrayList<JSONObject> doGetRequest() {
OkHttpClient client = new OkHttpClient();
ArrayList<JSONObject> departureObject = new ArrayList<>();
String url = "http_url";
Request request = new Request.Builder().url(url).build();
client.newCall(request).enqueue(new Callback() {
#Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
#Override
public void onResponse(Call call, Response response) throws IOException {
if(response.isSuccessful()) {
try {
String jsonData = response.body().string();
JSONObject Jobject = new JSONObject(jsonData);
JSONArray jarray = Jobject.getJSONArray("Flights");
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
String adft = object.getString("Adft");
if (adft.equals("D")) {
departureObject.add(object);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
return departureObject;
Hitting Api in android not getting immediately return data it depends upon your response.
you are to return the list immediately so you received an empty list if you can work inside the onResponse method then your problem is solved.
Don't use .equals() method on String, but use .contentEquals(). The reason for this is because contentEquals() checks the content of a String and compares it to StringBuffer, StringBuilder and CharSequence aswell and all derived classes of these.
This is why in your case adft.equals("D") could return false even though adft is in the background this:
String adft = "D";
The reason for that is because equals() will only compare String objects, so all other objects are considered not equal and it will return false.
More on that here: https://www.programmersought.com/article/2993983603/
Also, sometimes returned values can store a space we dont need, so insted "D" we have "D " or " D". To solve this just use method .trim()
if(adft.trim().contentEquals("D"))
You're returning the list immediately after enqueue your API. Your ArrayList fill after API request succeeds so you have to create your ArrayList global and fill that after onSuccess. After that create another method to render your data on UI. like mentioned below:
ArrayList<JSONObject> departureObject = new ArrayList<>();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activty_departures);
doGetRequest();
}
private void doGetRequest() {
OkHttpClient client = new OkHttpClient();
String url = "http_url";
Request request = new Request.Builder().url(url).build();
client.newCall(request).enqueue(new Callback() {
#Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
#Override
public void onResponse(Call call, Response response) throws IOException {
if(response.isSuccessful()) {
try {
String jsonData = response.body().string();
JSONObject Jobject = new JSONObject(jsonData);
JSONArray jarray = Jobject.getJSONArray("Flights");
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
String adft = object.getString("Adft");
if (adft.equals("D")) {
departureObject.add(object);
}
}
reloadData();
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
private void reloadData() {
// here your data is ready
}
I am trying to order my JSON data by name, I've found some answers here, but nothing works for my case. I have tried to update my code as you see below. I marked there what I have removed from original code, and what have I added:
#Override
protected Boolean doInBackground(String... args) {
HttpHandler sh = new HttpHandler();
String url = "androidnews.json";
String jsonStr = sh.makeServiceCall(url);
if (jsonStr != null) {
try {
//removed this:
//JSONObject jsonObj = new JSONObject(jsonStr);
//JSONArray actors = jsonObj.getJSONArray("result");
//ADDED:
ArrayList<JSONObject> array = new ArrayList<JSONObject>();
JSONArray actors = new JSONArray("result");
for (int i = 0; i < actors.length(); i++) {
JSONObject c = actors.getJSONObject(i);
//ADDED:
array.add(actors.getJSONObject(i));
Actors actor = new Actors();
actor.setName(c.getString("name"));
actor.setThumb(c.getString("thumb"));
actorsList.add(actor);
}
//ADDED:
Collections.sort(array, new Comparator<JSONObject>() {
#Override
public int compare(JSONObject lhs, JSONObject rhs) {
// TODO Auto-generated method stub
try {
return (lhs.getString("name").toLowerCase().compareTo(rhs.getString("name").toLowerCase()));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
}
});
} catch (final JSONException e) {
Zoznam.this.runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(Zoznam.this.getApplicationContext(),
"Data error " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}); }
return true;
} else {
Zoznam.this.runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(Zoznam.this.getApplicationContext(),
"Chyba internetového pripojenia.",
Toast.LENGTH_LONG).show();
}
});
return false;
}
}
But after I test it, I have this error: Value result of type java.lang.String cannot be converted to JSONArray
My JSON begins with: {"result": [{"name": "Joe","thumb": "image.jpg",...
Instead of sorting your JSONArray try sorting your Arraylist with custom object and use it. you can do something like this
Collections.sort(actorsList, new Comparator<Actors>() {
#Override
public int compare(Actors lhs, Actors rhs) {
return lhs.getName().compareTo(rhs.getName());
}
});
A solution to your current problem:
Im guessing that you are using the org.json library.
Currently you are trying to create a JSONArray from the string "result".
This is how you access an array within the JSON file:
JSONObject obj = new JSONObject(Files.readAllLines(Paths.get("/path/to/your/file.json")));
JSONArray arr = obj.getJSONArray("number");
Source: more helpful examples like the one above
Further information:
As it seems like your not to familiar with the org.json approach I would highly recommend taking a look at gson as it provides an easy way to map JSON entries to objects (or even Arrays of an Object).
See: this and this
I am working on a project.. when i have run my project in 2.2 version avd its work fine in my way.... but when i used AsyncTask in my code and run on 4.0 version avd its not work properly... i have found following errors in my logcat
Error parsing data java.net.SocketException: Socket closed
Error parsing data org.json.JSONException: No value for customer
can i implement properly the AsyncTask in my code?
please check my code ... what's going to wrong is this....
public class Login extends Activity {
String success, cus_id, cus_name;
SessionManager session;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Button submit = (Button) findViewById(R.id.loginbutton);
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// TODO Auto-generated method stub
com.amplio.MyCustomEditText et = (com.amplio.MyCustomEditText) findViewById(R.id.etmob);
String mobileno = et.getText().toString();
if (mobileno.length() > 0) {
final ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("cus_mob",
mobileno));
Thread thread = new Thread() {
#Override
public void run() {
try {
String response = null;
response = LoginHttpClient
.executeHttpPost(
"http://10.0.2.2/android/mobile_no.php",
postParameters);
System.out.println(response);
JSONObject json = new JSONObject(response);
JSONArray jArray = json
.getJSONArray("customer");
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray
.getJSONObject(i);
success = json_data.getString("success");
cus_id = json_data.getString("cus_id");
cus_name = json_data.getString("cus_name");
}
if (success.equals("1")) {
session = new SessionManager(
getApplicationContext());
session.createLoginSessionRemMe(cus_id,
cus_name);
Intent iv = new Intent(
getApplicationContext(),
Verify.class);
startActivity(iv);
} else {
// not valid email id or pass
Toast.makeText(getApplicationContext(),
"Incorrect Mobile No",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
}
}
};
thread.start();
}
else {
// display message if text fields are empty
Toast.makeText(getBaseContext(), "Mobile no is required",
Toast.LENGTH_SHORT).show();
}
}
});
}}
This question already has an answer here:
how to fix getDataTask method error?
(1 answer)
Closed 9 years ago.
this is my code below which work perfectly only problem is not show toast mesage code is blast i want to display toast mesage if Status is 0 in this line if (status.equals("1"))
show toast message but code is blast if i comment Toast then code run perfectly help me what do i do??
public class thirdstep extends Activity {
ListView listCategory;
String status;
String message;
String MenuSelect;
ProgressBar prgLoading;
long Cat_ID;
String Cat_name;
String CategoryAPI;
int IOConnect = 0;
TextView txtAlert;
thirdstepAdapter cla;
static ArrayList<String> Category_ID = new ArrayList<String>();
static ArrayList<String> Category_name = new ArrayList<String>();
static ArrayList<String> Category_image = new ArrayList<String>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.category_list2);
ImageButton btnback = (ImageButton) findViewById(R.id.btnback);
listCategory = (ListView) findViewById(R.id.listCategory2);
prgLoading = (ProgressBar) findViewById(R.id.prgLoading);
txtAlert = (TextView) findViewById(R.id.txtAlert);
cla = new thirdstepAdapter(thirdstep.this);
new getDataTask().execute();
listCategory.setAdapter(cla);
btnback.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0) {
// TODO Auto-generated method stub
finish();
}
});
Intent iGet = getIntent();
Cat_ID = iGet.getLongExtra("category_id", 0);
Cat_name = iGet.getStringExtra("category_name");
Toast.makeText(this, Cat_ID + Cat_name, Toast.LENGTH_SHORT).show();
MenuSelect = Utils.MenuSelect;
listCategory.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
Intent iMenuList = new Intent(thirdstep.this,
fourthscreen.class);
iMenuList.putExtra("Cat_ID",Cat_ID);
iMenuList.putExtra("Menuitem", Category_ID.get(position));
startActivity(iMenuList);
}
});
}
void clearData() {
Category_ID.clear();
Category_name.clear();
Category_image.clear();
}
public class getDataTask extends AsyncTask<Void, Void, Void>{
getDataTask(){
if(!prgLoading.isShown()){
prgLoading.setVisibility(0);
txtAlert.setVisibility(8);
}
}
#Override
protected void onPreExecute() {
// TODO Auto-generated method stub
}
#Override
protected Void doInBackground(Void... arg0) {
// TODO Auto-generated method stub
parseJSONData();
return null;
}
#Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
prgLoading.setVisibility(8);
if((Category_ID.size() > 0) || IOConnect == 0){
listCategory.setVisibility(0);
listCategory.setAdapter(cla);
}else{
txtAlert.setVisibility(0);
}
}
}
public void parseJSONData() {
CategoryAPI = Utils.MenuList + Cat_ID;
clearData();
try {
HttpClient client = new DefaultHttpClient();
HttpConnectionParams
.setConnectionTimeout(client.getParams(), 15000);
HttpConnectionParams.setSoTimeout(client.getParams(), 15000);
HttpUriRequest request = new HttpGet(CategoryAPI);
HttpResponse response = client.execute(request);
InputStream atomInputStream = response.getEntity().getContent();
BufferedReader in = new BufferedReader(new InputStreamReader(
atomInputStream));
String line;
String str = "";
while ((line = in.readLine()) != null) {
str += line;
}
JSONObject json = new JSONObject(str);
JSONObject json2 = new JSONObject(str);
status = json2.getString("status");
message = json2.getString("message");
if (status.equals("1")) {
JSONObject data = json.getJSONObject("data");
JSONArray school = data.getJSONArray("menu_groups");
for (int i = 0; i < school.length(); i++) {
JSONObject object = school.getJSONObject(i);
Category_ID.add(object.getString("id"));
Category_name.add(object.getString("title"));
Category_image.add(object.getString("image"));
}
}
else
{
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
IOConnect = 1;
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Your toast message is within the parseJsonData method which is called from the doInBackground method of your asynctask.
You can not update the user interface thread from a background thread.
You have two options here
1) You can publish the progress publishProgress(1) of the thread passing in an integer value to be used as a flag which you can pick up on in the onPublishProgress listener and show your toast there
or
2) As your method has finished by this point then make the parseJsonData set an integer variable global to the asynctask and in the onPostExecute method pass something back to the listener to indicate that a toast needs to be shown
Update based on comments
Replace
{
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
with
{
publishProgress(1);
}
Add the missing onProgressUpdate() method to your asynctask
#Override
protected void onProgressUpdate(Integer... percent) {
//Call your listeners.onProgressUpdate(percent) here and show the
//Or
super.onProgressUpdate(percent);
if (percent[0] == 1){
Toast.makeText(thirdstep.this, message, Toast.LENGTH_SHORT).show();
}
}
I'm not here to write your code for you. Do some research on how to properly write an async task and publish progress
Here is a good starting point
http://androidresearch.wordpress.com/2012/03/17/understanding-asynctask-once-and-forever/
You should be aware of orientation changes and how that will effect your asynctask (I avoid the pitfals of this by using a fragment
This is the design pattern I use for async tasks
http://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html
But for handling web services, be nice to your users and let the android system work out when to download data etc and don't drain their battery and use a sync adapter with an intentservice instead of an asynctask. There are already too many crappy apps out there that take the asynctask approach for consuming web services. Please don't add yours to the list
Do it this way
http://developer.android.com/training/sync-adapters/creating-sync-adapter.html
It's a lot of extra learning curve but your a programmer right? You should be giving your users the best possible experience.
BTW You are getting down votes because you are demanding code to be written for you. I'm hoping this is just a language barrier and not an attitude problem.
Surround your Toast with this
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getBaseContext(), message, Toast.LENGTH_SHORT).show();
}
});
I am trying to pass a string array to my adapter. My problem is i initialized globally and try to create string array in my asynchronous task below. But i am getting as null. Below is my code. Actually in this example they taking it from resource folders bu i want it from my json response. Any help is appreciated.
String[] mString;
public ActionsAdapter(Context context) {
mInflater = LayoutInflater.from(context);
session = new SessionManager(context);
final Resources res = context.getResources();
new ConnectAppMenu(context).execute();
// mTitles = res.getStringArray(R.array.actions_names);
// mUrls = res.getStringArray(R.array.actions_links);
// mIcons = res.obtainTypedArray(R.array.actions_icons);
System.out.println("Menus"+ mString);
}
public class ConnectAppMenu extends AsyncTask<String, Void, String> {
private ProgressDialog dialog;
private final Context context;
public ConnectAppMenu(Context context) {
this.context = context;
}
#Override
protected void onPreExecute() {
// UI work allowed here
dialog = new ProgressDialog(context);
// setup your dialog here
dialog.setMessage("Connecting....");
dialog.setCancelable(false);
dialog.show();
}
#Override
protected String doInBackground(String... params) {
String returnConnect = doConnectAppMenu();
return returnConnect;
}
public String doConnectAppMenu() {
HashMap<String, String> user = session.getUserDetails();
String client_url = user.get(SessionManager.KEY_CLIENT);
// if(connection) {
HttpParams connectionParameters = new BasicHttpParams();
int timeoutConnection = 8000;
HttpConnectionParams.setConnectionTimeout(connectionParameters, timeoutConnection);
int timeoutSocket = 10000;
HttpConnectionParams.setSoTimeout(connectionParameters, timeoutSocket);
HttpClient httpClient = new DefaultHttpClient(connectionParameters);
HttpPost httpPost = new HttpPost(client_url+"/api/common/app_menu");
JSONObject json = new JSONObject();
try{
json.put("data", 1);
json.put("versionid", 1);
StringEntity se = new StringEntity(json.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httpPost.setEntity(se);
//Execute HTTP post request
appmenu_res = httpClient.execute(httpPost);
appmenu_obj = new org.json.JSONObject(org.apache.http.util.EntityUtils.toString(appmenu_res.getEntity()));
appmenu_result = appmenu_obj.toString();
}
catch(JSONException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// }
return appmenu_result;
}
#Override
public void onPostExecute(String result) {
int status_code = appmenu_res.getStatusLine().getStatusCode();
if (status_code == 200) {
dialog.dismiss();
try {
menuObject = new JSONObject(result);
JSONArray names= menuObject.names();
JSONArray values = menuObject.toJSONArray(names);
for (int i = 0; i< values.length(); i++) {
JSONObject json2 = (JSONObject) values.get(i);
int menu_id = json2.getInt("menu_id");
if (menu_id > 0) {
if (json2.has("menu_name")) {
menu_list = json2.get("menu_name").toString();
mString = new String[] { menu_list };
//mUrls = menu_list.length();
}
}
}
System.out.println("Json Menu" + Arrays.toString(mString));
/*Iterator<String> iter = menuObject.keys();
while (iter.hasNext()) {
String key = iter.next();
try {
Object value = menuObject.get(key);
//System.out.println("Hai" +value);
System.out.println("Post Execute" + value);
} catch (JSONException e) {
// Something went wrong!
}
}*/
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//dialog.dismiss();
}
}
}
well first of all if you're looking for the JSON object as a String don't do what you did here:
appmenu_obj = new org.json.JSONObject(org.apache.http.util.EntityUtils.toString(appmenu_res.getEntity()));
I'd suggest doing the following:
String Json = EntityUtils.toString(appmenu_res.getEntity());
return Json;
Now if you want to do the processing of your JSON on the UI thread (as you seem to want to based on the return type being a string) this should work. However this method is not recommended since the Json will need to be processed into objects which will take time and clog the UI thread.
A better solution would be to serialize your Json on the background thread and then pass the serialized object back to the main thread to update the UI.
If you have many types I would suggest using generics. I've already built a Loader which can do what you want if you want here. You will need touse the GSON library and build appropriate seralizers. Also working with the loader class is different to working with the AsyncTaskClass so please read the documentation here
Edit
Ok so what you want to do if you want get the Activity to have a callback from the AsyncTask is to do something along the lines of:
public class MyActivity extends Activity implements AsyncTaskCallback
where AsyncTaskCallback looks something like :
public interface AsyncTaskCallback
{
public processData(Object responseObject);
}
now in your onPostExecute code you'll need to do somehting like:
#Override
protected void onPostExecute(Object r){
if (r != null) {
l.processData(data);
}
}
and add the following function to your async task
public void addAsyncTaskListener (final AsyncTaskListener l){
mCallback = l;
}
and then finally add the listner and process the data as required in the Activity in the function processData function that the interface forces your activity to implement.
Instead of using String[] you can use ArrayList for Setting list in adaptor.