How my app can know when user logout from its native Facebook app ?
I am using below code for Logging out from Facebook in my app. And it is working fine.
class LogoutTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
if (facebook.isSessionValid()) {
try {
facebook.logout(getApplicationContext());
editLoginStatus(false);
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", null);
editor.putLong("access_expires",
facebook.getAccessExpires());
editor.commit();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
}
But problem is occurring when user logging out from its native Facebook app and then clicking on the logout button on my app.
It showing me following error
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.IllegalArgumentException: Invalid context argument
at android.webkit.CookieSyncManager.createInstance(CookieSyncManager.java:86)
at com.facebook.internal.Utility.clearCookiesForDomain(Utility.java:319)
at com.facebook.internal.Utility.clearFacebookCookies(Utility.java:343)
at com.facebook.Session.closeAndClearTokenInformation(Session.java:798)
at com.facebook.android.Facebook.logoutImpl(Facebook.java:665)
at com.facebook.android.Facebook.logout(Facebook.java:642)
at com.example.animation.StartLoginActivity$LogoutTask.doInBackground(StartLoginActivity.java:328)
at com.example.animation.StartLoginActivity$LogoutTask.doInBackground(StartLoginActivity.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
and I am calling this function as below
if (facebook.getAccessToken() != null && facebook.isSessionValid() == true) {
new LogoutTask().execute();
}
here accessToken I am storing locally in sharedPreference , so it won't be null as long as I am not logging out from my app , but I guess after logging out from native FB app facebook.isSessionValid()
should return false while it is returning true .So how to check to know Facebook app is already logging out or not ?