-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blocks all application's AsyncTask executions on Android 4.x #4
Comments
A quick fix seems to override onBackPressed() in your activity and send a message to the view's async task notifyAuthorization() method. For example: @Override
public void onBackPressed () {
twitterView.notifyBackButtonPress();
super.onBackPressed();
} In the //add this line below private static final boolean DEBUG = false
private TwitterOAuthTask asyncTask;
//Change the start(..) method to this:
public void start(String consumerKey, String consumerSecret, String callbackUrl, boolean dummyCallbackUrl,
Listener listener)
{
if (consumerKey == null || consumerSecret == null || callbackUrl == null || listener == null)
{
throw new IllegalArgumentException();
}
Boolean dummy = Boolean.valueOf(dummyCallbackUrl);
asyncTask = new TwitterOAuthTask();
asyncTask.execute(consumerKey, consumerSecret, callbackUrl, dummy, listener);
}
//add these methods somewhere in TwitterOAuthView class
public TwitterOAuthTask getAsyncTask() {
return asyncTask;
}
public void notifyBackButtonPress() {
getAsyncTask().notifyAuthorization();
}
This is working for me on 4.X |
Thanks for the tip. However, from a quick glance at the code, it seems to me that, as the result of the Furthermore, this issue is the cause of #3 and the overriding of |
It sounds that there should be a mechanism to cancel the AsyncTask from outside. |
I added cancel() method which enables to cancel a running AsyncTask. In addition, TwitterOAuthView now overrides onDetachedFromWindow() and the implementation calls cancel() method from within it. This means that cancel() is automatically executed. You can enable/disable this automatic call by setCancelOnDetachedFromWindow(boolean). I hope these changes solve the issues your are facing. |
I did solve the issue myself (but did not find the time to contribute back some code) by breaking your suspended |
Is there any confirmation this has been fixed? |
When
TwitterOAuthView
has loaded Twitter's application authorization form, and the user navigates away from the fragment or activity containing the view, the underlyingTwitterOAuthTask
(which extendsAsyncTask
) remains blocked, as a result of the call toObject.wait()
in itswaitForAuthorization()
method. However, this means that, on Android 4.x where only oneAsyncTask
can be executed at a time, any otherAsyncTask
belonging to the application will never start untilTwitterOAuthTask
receives a proper notification viaObject.notify()
, which will never be called.As a side effect, on Android 4.x it's also impossible to load
TwitterOAuthView
two times in a row if the first time the user has navigated away from the fragment or activity containing the view, because theAsyncTask
that loads Twitter's authorization page cannot be executed until the previous blockedAsyncTask
receive anObject.notify()
call.The text was updated successfully, but these errors were encountered: