Created
June 13, 2011 07:17
-
-
Save Yincan/1022415 to your computer and use it in GitHub Desktop.
Android Activity LaunchMode attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<activity android:launchMode = ["standard" | "singleTop" | "singleTask" | "singleInstance"] ../> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void onNewIntent(Intent intent) { | |
super.onNewIntent(intent); | |
Uri uri = intent.getData(); | |
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) { | |
String verifier = uri.getQueryParameter("oauth_verifier"); | |
try { | |
//load other persisted data goes here | |
.... | |
//get the request-token from prefs and request the access token | |
TwitterFactory twitter = new TwitterFactory().getInstance(); | |
requestToken = prefsManager.getRequestToken(); | |
prefsManager.clearTwitterRequestToken(); | |
twitter4j.auth.AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier); | |
// save the access token | |
prefsManager.saveTwitterOauth(accessToken.getToken(), accessToken.getTokenSecret(), accessToken | |
.getScreenName()); | |
//other logics to do the post to twitter | |
.... | |
} catch (Exception e) { | |
Log.e(TAG, e.getMessage(), e); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<activity android:name=".MainTabActivity" android:launchMode="singleTask" android:alwaysRetainTaskState="true" android:windowSoftInputMode="adjustPan"> | |
</activity> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<activity android:name=".NewsDetailActivity" android:launchMode="singleTop"> | |
<intent-filter> | |
<action android:name="android.intent.action.VIEW"></action> | |
<category android:name="android.intent.category.DEFAULT"></category> | |
<category android:name="android.intent.category.BROWSABLE"></category> | |
<data android:scheme="oauth" android:host="twitt"></data> | |
</intent-filter> | |
</activity> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void twitterOAuth() { | |
try { | |
System.setProperty("twitter4j.http.useSSL", "false"); | |
System.setProperty("twitter4j.oauth.consumerKey", getString(R.string.twitter_oauth_consumer_key)); | |
System.setProperty("twitter4j.oauth.consumerSecret", getString(R.string.twitter_oauth_consumer_secret)); | |
System.setProperty("twitter4j.oauth.requestTokenURL", "http://api.twitter.com/oauth/request_token"); | |
System.setProperty("twitter4j.oauth.accessTokenURL", "http://api.twitter.com/oauth/access_token"); | |
System.setProperty("twitter4j.oauth.authorizationURL", "http://api.twitter.com/oauth/authorize"); | |
// get the instance | |
Twitter twitter = new TwitterFactory().getInstance(); | |
twitter4j.auth.RequestToken requestToken = twitter.getOAuthRequestToken(CALLBACK_URL); | |
//save the request token and secret | |
prefsManager.saveTwitterRequestToken(requestToken.getToken(), requestToken.getTokenSecret()); | |
//save other data | |
persistNewsDatas(); | |
//start the browser activity | |
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())); | |
startActivity(intent); | |
} catch (Exception e) { | |
Log.e(TAG, e.getMessage(), e); | |
Toast.makeText(NewsDetailActivity.this, "Fail to connect to twitter now, please try later.", | |
Toast.LENGTH_SHORT).show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this example correct? It always creates new instance of the NewsDetailActivity when returning back from Twitter web page.