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

  • SEARCH
  • Home
  • 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 7546611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:14:38+00:00 2026-05-30T09:14:38+00:00

I am trying to integrate facebook capabilities into my Android app. So, I have

  • 0

I am trying to integrate facebook capabilities into my Android app. So, I have an adapter which is going to display a list of items. Once user clicks on a button, it will start the authentication/authorizing process. But I am having errors on my code. Have I missed out any declarations or anything? I am following the example from here

Error 1: MODE_PRIVATE cannot be resolved to a variable

Error 2: The method onActivityResult(int, int, Intent) is undefined for the type BaseAdapter

Adapter.java

public class LazyAdapter extends BaseAdapter {

Facebook facebook = new Facebook("132789674563789674");
private Activity activity;
private String[] data;
private String[] text;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;

private static final String APP_ID = "132789674563789674";
private ProgressDialog mProgress;
private Handler mRunOnUi = new Handler();

String FILENAME = "AndroidSSO_data";
private SharedPreferences mPrefs;

public LazyAdapter(Activity a, String[] d, String[] t) {
    activity = a;
    data=d;
    text = t;
    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(final int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    ViewHolder holder;
    if(convertView==null){
        vi = inflater.inflate(R.layout.item, null);
        holder=new ViewHolder();
        holder.text=(TextView)vi.findViewById(R.id.text);;
        holder.image=(ImageView)vi.findViewById(R.id.image);
        vi.setTag(holder);

        ImageButton fbBtn = (ImageButton) vi.findViewById(R.id.fb);

        fbBtn.setOnClickListener(
                new Button.OnClickListener() {
                    public void onClick(View v) 
                    {
                        /*
                         * Get existing access_token if any
                         */
                        mPrefs = getPreferences(MODE_PRIVATE);    <--- MODE_PRIVATE cannot be resolved to a variable
                        String access_token = mPrefs.getString("access_token", null);
                        long expires = mPrefs.getLong("access_expires", 0);
                        if(access_token != null) {
                            facebook.setAccessToken(access_token);
                        }
                        if(expires != 0) {
                            facebook.setAccessExpires(expires);
                        }

                        /*
                         * Only call authorize if the access_token has expired.
                         */
                        if(!facebook.isSessionValid()) {


                        facebook.authorize(activity, new String[] {"publish_stream", "publish_checkins"}, new DialogListener() {
                            @Override
                            public void onComplete(Bundle values) 
                            {
                                //postToFacebook(String image);
                                SharedPreferences.Editor editor = mPrefs.edit();
                                editor.putString("access_token", facebook.getAccessToken());
                                editor.putLong("access_expires", facebook.getAccessExpires());
                                editor.commit();
                            }

                            @Override
                            public void onFacebookError(FacebookError error) {}

                            @Override
                            public void onError(DialogError e) {}

                            @Override
                            public void onCancel() {}
                        });
                    }
                }
                    }
            );

    }
    else
    holder=(ViewHolder)vi.getTag();

    holder.text.setText(text[position]);
    holder.image.setTag(data[position]);
    imageLoader.DisplayImage(data[position], activity, holder.image);
    return vi;

postToFacebook("");       
}//close getView


private void postToFacebook(String data) {  
    mProgress.setMessage("Posting ...");
    mProgress.show();

    AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(facebook);

    Bundle params = new Bundle();

    params.putString("message", "Visit me here!");
    params.putString("name", "My Name");
    params.putString("caption", "google.com");
    params.putString("link", "http://www.google.com");
    params.putString("description", "Visit the search engine");
    params.putString("image", data);

    mAsyncFbRunner.request("me/feed", params, "POST", new WallPostListener());
}//close posttofacebook

private final class WallPostListener extends BaseRequestListener {
    public void onComplete(final String response) {
        mRunOnUi.post(new Runnable() {
            @Override
            public void run() {
                mProgress.cancel();

                Toast.makeText(activity, "Posted to Facebook", Toast.LENGTH_SHORT).show();
            }
        });
    }//close oncomplete
}//close wallpostlistener

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);  <----- The method onActivityResult(int, int, Intent) is undefined for the type BaseAdapter

    facebook.authorizeCallback(requestCode, resultCode, data);
}


}
  • 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-30T09:14:40+00:00Added an answer on May 30, 2026 at 9:14 am

    Problems:

    Error 1: MODE_PRIVATE cannot be resolved to a variable

    getPreferences() and MODE_PRIVATE are not available in BaseAdapter, these both are available in Context class (so it is also available in Activity) and you can access them using context.getPreferences(Context.MODE_PRIVATE);

    Error 2: The method onActivityResult(int, int, Intent) is undefined
    for the type BaseAdapter

    onActivityResult() is method of Activity not a method of BaseAdapter

    Solution:

    You should put facebook authentication and post to wall related code in Activity.

    and now the point is:

    • how Activity will know the FB ImageButton was pressed.
    • how Activity will know that it should do postToFacebook(String);

    We will use interface, make an interface in your LazyAdapter like this:

    public class LazyAdapter extends BaseAdapter {
        FBookTaskListener taskListener;
    //--all your other class members as above in your code.
        public void setTaskListener(FBookTaskListener listener)
        {
            this.taskListener = listener;
        }
    
    //-- here all your other stuff constructor getView() getCount() etc. as above in your code.
    
        public static interface FBookTaskListener{
            public void doAuthentication(); //paramas may be added if needed
            public void postToWall();  //paramas may be added if needed
        }
    }
    

    now in your LazyAdapter‘s getView() where you set OnClickListener for FBButton

    fbBtn.setOnClickListener(new Button.OnClickListener() {
         public void onClick(View v)
         {
              taskListener.doAuthentication();  // will be handled in Activity :)
         }
    });
    

    now in your Activity where you set Adapter.

    LazyAdapter adapter = new LazyAdapter(this, a, b);
    listView.setAdapter(adapter);
    adapter.setTaskListener(new FBookTaskListener(){
        public void doAuthentication()
        {
                // here all your FB authentication related stuff.
        }
        public void postToWall()
        {
            postToFacebook();
        }
    });
    

    take all method like onActivityResult() and postToFacebook() and WallPostListener in your Activity class from LazyAdapter

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

Sidebar

Related Questions

I'm trying to integrate Facebook into my Android Java app, what I want it
I'm trying to retrieve in my android app(in which I have facebook integrated )
I'm trying to integrate a Facebook send button into my site using Facebook app.
I'm trying to integrate the Facebook Android SDK in my app, but I can't
I'm trying to integrate Facebook into a site I'm developing, I have created a
I'm trying to integrate facebook graph into my app. I've tried to follow the
I'm trying to integrate facebook login on my android app. I found a lot
I am trying to integrate Facebook into a web app that I am working
I've been trying to integrate Facebook Credit purchases into my app, but any call
I am trying to integrate facebook with android mobile, all i need to do

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.