Comments (6)
A quick fix seems to override onBackPressed() in your activity and send a message to the view's async task notifyAuthorization() method.
For example:
In your Activity w/ the twitter view
@Override
public void onBackPressed () {
twitterView.notifyBackButtonPress();
super.onBackPressed();
}
In the TwitterOAuthView
//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
from twitteroauthview.
Thanks for the tip.
However, from a quick glance at the code, it seems to me that, as the result of the AsyncTask
's notification, the listener's onFailure
method will be called, suggesting a failure to obtain Twitter's authorization, while indeed there's not even been an attempt at doing so.
Furthermore, this issue is the cause of #3 and the overriding of onBackPressed
would not work in that case.
from twitteroauthview.
It sounds that there should be a mechanism to cancel the AsyncTask from outside.
from twitteroauthview.
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.
from twitteroauthview.
I did solve the issue myself (but did not find the time to contribute back some code) by breaking your suspended AsyncTask
into two tasks, the first retrieving Twitter's request token with the authorization URL, the second getting Twitter's access token after the user has authorized the application from the displayed web page. That seemed to give me some greater degree of peace of mind than fiddling with wait()
and notify()
while failing to see the need to. I would probably spend some more time making my code more reliable now, and proceed from there for any future application. However, regarding your solution, I still do believe that a BACK or a cancellation should not result in an onFailure()
call, because you'd miss a way to distinguish a real failure (which the user should be notified about by some dialog or message) from a user's change of mind (which needs no on-screen notification at all).
from twitteroauthview.
Is there any confirmation this has been fixed?
from twitteroauthview.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twitteroauthview.