Question

Working with facebook in Android. Sometimes my application is cashing in real time device when I tried to authorize Facebook in Android.not in emulator. I used the Android Facebook SDK. So I thought threading might stop that.First tried the asynctask

Activity act=this;

private class fbwork extends AsyncTask<Facebook, Integer, String>
{

    @Override
    protected String doInBackground(Facebook... para)
    {
        // TODO Auto-generated method stub
        Log.d(tagg, "Entered async");
            if(loginflag==0)
            {
                try
                {
                    para[0].authorize(act, PERMISSIONS, new LoginDialogListener());
                }catch(Exception ex)
                {
                    Log.d(tagg,ex.getMessage());
                }
                Log.d(tagg, tagg.toString());
            }
            else
            {

                try {
                    logout();
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }


        return "0";
    }

calling code:

new fbwork().execute(facebook);

produce error: Can't create handler inside thread that has not called Looper.Prepare()

So tried the normal threading way.

public void loginprocesure() throws MalformedURLException, IOException
{
    final Activity ac=this;
    if(loginflag==0)
    {
        new Thread(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub
                facebook.authorize(ac, PERMISSIONS, new LoginDialogListener());
            }
        }).start();

    }
    else
    {

        logout();
    }
}

Again same result. any way to fix this!!!! How to stop that crashing of application in real device. Please help.

Was it helpful?

Solution

I faced the same issue.You must try to put this method in loop

 Looper.prepare();
 new fbwork().execute(facebook);
 Looper.loop();

OTHER TIPS

Facebook authorize uses methods which access event thread, so you dont need to execute this method into another thread, than event thread.

If you face issue in execution of this method in normal event thread, specifythat issue.

I'm having this problem too. I couldn't get the AsyncTask code working.

So I ended up using runOnUiThread. It works on the emulator, but not on the device, I'm using HTC Desire Android SDK 2.2.2. Unfortunately, I can't even login to Facebook using Hackbook (Facebook's sample project).

Here's code that uses runOnUiThread: Android App Crashes after Sharing using Facebook Dialogs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top