Facebook allows not working inside Android Asynctask or Thread

Work with facebook on Android. Sometimes my application gives money in real time when I tried to allow Facebook in Android.not in the emulator. I used the Android Facebook SDK. So I thought threads could stop this. At first I tried asintasku

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"; } 

call code:

 new fbwork().execute(facebook); 

create error: cannot create handler inside thread that did not call Looper.Prepare ()

So, I tried the usual sequence of threads.

 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 the same result. any way to fix this !!!! How to stop this application crash on a real device. Please, help.

+4
source share
3 answers

I ran into the same problem. You should try to apply this method in a loop.

  Looper.prepare(); new fbwork().execute(facebook); Looper.loop(); 
+2
source

Facebook authorize uses methods that access the event stream, so you do not need to execute this method on a stream other than the event stream.

If you encounter a problem while executing this method in a normal event stream, indicate this problem.

0
source

I have such a problem too. I could not get the AsyncTask code.

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

Here is the code that uses runOnUiThread: Android application crashes after sharing using Facebook dialogs

0
source

Source: https://habr.com/ru/post/1397154/


All Articles