Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8985117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:15:43+00:00 2026-06-15T21:15:43+00:00

i use AsyncTask inside a function How to return a value when Async Finish

  • 0

i use AsyncTask inside a function
How to return a value when Async Finish Execution , since i cant use PostExecute method here

AsyncTask.execute(new Runnable() {
            public void run() {}}

Heres The Code.
I need to retrieve values from SpinnerList to use em on the main thread.
But usually i get null values whenever i ask for data , because it didnt return the values yet.

AsyncTask.execute(new Runnable() {
            public void run() {
                try{
                    String fql = "SELECT uid, name FROM user WHERE is_app_user  AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
                    Bundle parameters = new Bundle();

                    parameters.putString("query", fql);
                    parameters.putString("method", "fql.query");
                    parameters.putString("access_token",  fb.getAccessToken());
                    String Response = fb.request(parameters);
                    JSONArray json = new JSONArray(Response);
                    list = new ArrayList<String[][]>();
                    String[][] friendsToList = new String[1][2];
                    SpinnerList = new ArrayList<String>();
                    String TempToSpinnerList=new String();
                    for(int i = 0; i < json.length(); ++i){
                        friendsToList[0][0] = json.getJSONObject(i).getString("uid");
                        friendsToList[0][1] = json.getJSONObject(i).getString("name");
                        TempToSpinnerList= friendsToList[0][1];
                            list.add(friendsToList);
                            SpinnerList.add(TempToSpinnerList);
                            Log.e("Test"," "+friendsToList[0][1]+" "+friendsToList[0][0]);
                        }


                        //dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                        //spinner.setAdapter(dataAdapter);



    /*  jsonUser = fb.request(parameters);
        friendObj = Util.parseJson(jsonUser);

        friendArray = friendObj.getJSONArray("data");

        //
        friendlist = new ArrayList<String[][]>();
        String[][] friendsToList = new String[1][2];
        int friendCount = 0;
        String fId, fNm;
        JSONObject friend;
        for (int i = 0;i<friendArray.length();i++){
            //Get a JSONObject from the JSONArray
            friend = friendArray.getJSONObject(i);
            //Extract the strings from the JSONObject
           friendsToList[0][0] = friend.getString("id");
            friendsToList[0][1] = friend.getString("name");
            friendlist.add(friendsToList);
            //Set the values to our arrays
         Log.e("Tester",""+ friendsToList[0][0]+" "+ friendsToList[0][1]);
            friendCount ++;}*/
            }
                catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (FacebookError e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }   
            }});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:15:44+00:00Added an answer on June 15, 2026 at 9:15 pm

    If you want to perform some function once the Asynctask is complete, you can setup a callback function in the calling activity. Create a constructor in the AsyncTask class and pass it the calling activity. Then use this reference to call the callback function when your task is complete.

    You can also update the UI from within onPostExecute, which is simpler if it works for you.

    public class MyTask extends AsyncTask<String, Void, String>
    {
        private MainActivity activity;
    
        public MyTask(MainActivity activity) {
            this.activity = activity;
        }
        @Override
        protected Void doInBackground(String... params) {
            //Do background stuff
        }
    
        protected void onPostExecute() {
            //dismiss progress dialog if needed
            //Callback function in MainActivity to indicate task is done
            activity.taskDone("some string");
        }
    }
    

    MainActivity.java

    //Pass your params array and the current activity to the AsyncTask
    new MyTask(MainActivity.this).execute(params);
    
    //Callback for AsyncTask to call when its completed
    public void taskDone(String returnVal) {
        //Do stuff once data has been loaded
        returnText = returnVal;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use doInBackground method of AsyncTask to send a message to a
I am learning AsyncTask,I tried to print Toast message inside doInBackground method,is it possible
I noticed one interesting thing with my app ( I use Jsoup inside AsyncTask)
In my application I use AsyncTask in oncreate . Sometimes I get Launch timeout
I want to lock back button while my data process. I use AsyncTask to
In my Activity I use multiple AsyncTask classes. How to cancel AsyncTask when Activity
I am using AsyncTask and want to use getApplication() to work with class Application.
I am new to async task . I need to use httppost in my
I have a backgorund thread that extends AsyncTask and which I use in activity
I use an AsyncTask for loading operations that I implemented as an inner class.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.