Android - Facebook Log Out Error

摘要:Android - Facebook Log Out Error

在Facebook分享完後,並且啟動Logout,結果發生了錯誤

FATAL EXCEPTION: main
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)

查到網路解如下:

http://stackoverflow.com/questions/13339393/facebook-log-out-error-in-android

 

說明是如下

This exception is thrown when an application attempts to perform a networking operation on its main thread. Run your code in AsyncTask or in Thread.

or Add below code in onCreate() method.

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy); 

所以我在onCreate加了

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

StrictMode.setThreadPolicy(policy); 

就正常了。