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 6162517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:40:05+00:00 2026-05-23T21:40:05+00:00

I have an app in android in which I return some data from facebook

  • 0

I have an app in android in which I return some data from facebook(some names and id’s) and right after I return this data I use an adapter to set all this names in a list view.
All this work I do it in onCreate().First time I use a method getData() to return some names from facebook and after that I call for the adapter.

The problem is that getData() returns in an array of Strings the names that will be setup up with the adapter.Now,the adapter called does some processing on this array.

How I return these names from web this part works slowly and the array is not filled in time so when the adapter gets called the array is still empty and I get force close.

this is how I do it:

private String[] mStrings;
private String[] fName;
public void onCreate(Bundle savedInstanceState)
{
        super.onCreate(savedInstanceState);
       setContentView(R.layout.invitefriends);

        ....................
   /*In here I request for friends from facebook which ae set up in an array*/
     mAsyncRunner.request("me/friends", new SampleRequestListener());

  /*here is the adapter that processes the arrays returned in SampleRequestListener*/

    adapter=new LazyAdapter1(this, mStrings,fName);
     list.setAdapter(adapter);

  }

/Here is the SampleRequestListener that does return from facebook the names in some arrays/

public class SampleRequestListener extends BaseRequestListener{
    int i;
    public void onComplete(final String response, final Object state){
        friends = new ArrayList<Friends>();
        try{
            Log.d("facebook-example","Response: " + response.toString());
            JSONObject json = Util.parseJson(response);
            JSONArray array = json.optJSONArray("data");


            if(array!=null){
                for(int i=0; i<array.length(); i++)
                {
                    String name=array.getJSONObject(i).getString("name");
                    String id= array.getJSONObject(i).getString("id");
                    Friends f=new Friends(name,id);
                    friends.add(f);
                    Log.d(name,id);
                }
                   mStrings = new String[friends.size()];
                    for(int i=0; i< mStrings.length; i++){
                        mStrings[i] = "http://graph.facebook.com/"+friends.get(i).getId()+"/picture?type=small";
                    }
                    fName = new String[friends.size()];
                    for(int i=0; i<friends.size(); i++)
                    {
                        fName[i]=friends.get(i).getName();
                    }

            }
        }
        catch(JSONException e)
        {
            //do nothing
        }
        catch(FacebookError e)
        {
            e.getMessage();
        }
    }
}

And finally here is the adapter’s body:

public class LazyAdapter1 extends BaseAdapter {

private Activity activity;
private String[] data;
private String[] nume;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 

public LazyAdapter1(Activity a, String[] d, String[] f) {
    activity = a;
    data=d;
    nume=f;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity.getApplicationContext());
}

public int getCount() {
    return data.length;
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public static class ViewHolder{
    public TextView text;
    public ImageView image;
}

public View getView(int position, View convertView, ViewGroup parent) {
    //........
}

}

The problem is that mStrings[] and fName[] are not returned in time by the background thread so they are still empty when I try to act with the adapter on them.

So could someone tell how should I proceed for this thing to work right??Thanks

  • 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-05-23T21:40:06+00:00Added an answer on May 23, 2026 at 9:40 pm

    use the AsyncTask class and extend with your custom class.

    this was good for getting the data in background process.

    and when the data are fetched then set into the adapter

    check this links

    http://www.vogella.de/articles/AndroidPerformance/article.html

    http://developer.android.com/reference/android/os/AsyncTask.html

    http://www.xoriant.com/blog/mobile-application-development/android-async-task.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an Android App that gets some data from a web server,
I have an app which could benefit from the user being able to choose
I have an Android app which by preference uses external storage if available to
Suppose I have my Android app's source code packaged this way: src/ my/ app/
I have an app with a large ListView which is terribly slow so I'm
We have an app with an extensive admin section. We got a little trigger
I have an app that needs to open a new window (in the same
I have an app using PHP and the PayPal API. The basic way it
I have an app written in C# that lies on a network share. When
I have an app where I create many uiviews and add them to the

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.