I have implement some operations with twitter in an application on the emulator works perfectly, but on the actual device, I have an exception:
android.os.NetworkOnMainThreadException
I have read about that error, and it is because I need to do a thread out of the main action, but not understand how to make the call to the function asyncsTask, since I need send Shared Preferences as a parameter. --------------------- I need put the function isAuthenticated or a part of his code in AsyncTask but need send prefs as parameter and I do not is how to do it
I put a part of the code.
HERE CALL
if (TwitterUtils.isAuthenticated(prefs)) {
......
.....
....
}
IN CLASS TwitterUtils.java
public static boolean isAuthenticated(SharedPreferences prefs) {
String token = prefs.getString(OAuth.OAUTH_TOKEN, "");
String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, "");
AccessToken a = new AccessToken(token,secret);
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
twitter.setOAuthAccessToken(a);
try {
twitter.getAccountSettings(); **LINE ERROR**
return true;
} catch (TwitterException e) {
e.printStackTrace();
return false;
}
Any solution?
Thanks