Currently I'm trying to implement a reusable Twitter status 'poster'. The Twitter status part of it is working, but the reusable bit isn't. Here's what I'm doing:
An activity called SummaryDisplay imports a class TweetStatus and calls a function sendStatus. It also implements a listener which is called when TweetStatus can confirm that the status was successfully sent. So far so good.
TweetStatus sends an intent to another activity, OAUTH, which will return with the user token and secret allowing us to 'login' to Twitter.
If OAUTH can't find any saved tokens and secrets, it sends an intent to the browser so the user can login to Twitter and confirm that our app is allowed to send tweets on their behalf. Twitter than uses a callback to return to the OAUTH application (by using an intent filter within the manifest we make our own android:scheme and host):
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="my-app" android:host="twitter-login-success" />
</intent-filter>
The callback URI is then:
private static final Uri CALLBACK_URI = Uri.parse("my-app://twitter-login-success");
It is because of this callback being an intent that the OAUTH class has to extend activity (so it can receive these intents).
So the problem is in OAUTH returning with the token and secret (shown in bold above). Currently OAUTH sends an intent to SummaryDisplay that then sends the data to TweetStatus. The problem is that the SummaryDisplay intent is hardcoded:
Intent i = new Intent(this, SummaryDisplay.class);
so the OAUTH class is no longer reusable as a new one will need to be made for each activity which wants to send a Twitter status.
One option is for the callback from Twitter to be changed to SummaryDisplay instead of OAUTH, but then this requires changing the callback to one of your choice (one not registered with Twitter and I need to check if that's allowed). Another option which I'm trying is to use StartActivityForResult.
So:
TweetStatus calls OAUTH with StartActivityForResult,
OAUTH calls the browser,
Browser then calls OAUTH back using a callback URI,
OAUTH returns result to whomever started it.
Therefore reusable. However the callback URI received from the browser is seemingly creating a new instance of OAUTH which has no idea who to callback, so just does nothing. I've tried setting the android:launchMode to singleInstance but this disables the result from being sent (with LogCat reporting):
09-08 10:22:00.742: WARN/ActivityManager(563): Activity is launching as a new task, so cancelling activity result.
Are there any other ways of doing this? Is there, for example, a way of sending a "class" of yourself in an intent which can then be used in
Intent i = new Intent(this, myClassVariableSetUsingAnIntent);
So I can then use
android:launchMode="singleInstance"
Thanks for any help.