Facebook 授权不能在 Android Asynctask 或 Thread 中工作 [英] Facebook authorize not working inside Android Asynctask or Thread
本文介绍了Facebook 授权不能在 Android Asynctask 或 Thread 中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Android 中使用 Facebook.有时,当我尝试在 Android 中授权 Facebook 时,我的应用程序正在实时设备中兑现.而不是在模拟器中.我使用了 Android Facebook SDK.所以我认为线程可能会阻止它.首先尝试异步任务
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";
}
调用代码:
new fbwork().execute(facebook);
产生错误:无法在未调用 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();
}
}
同样的结果.有任何解决这个问题的方法吗!!!!如何阻止应用程序在真实设备中崩溃.请帮忙.
推荐答案
我遇到了同样的问题.你必须尝试将这个方法放入循环中
I faced the same issue.You must try to put this method in loop
Looper.prepare();
new fbwork().execute(facebook);
Looper.loop();
这篇关于Facebook 授权不能在 Android Asynctask 或 Thread 中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文