twitter-kit-android
twitter-kit-android copied to clipboard
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
This happens in our React Native app. Possibly because the following method fails since the context is a react context and not an activity: https://github.com/twitter/twitter-kit-android/blob/38aeae6c046fe2ba1074a1f0cbfaf7746a8c76ce/twitter-core/src/main/java/com/twitter/sdk/android/core/IntentUtils.java#L34
Steps to reproduce the problem
- Implement TwitterTweet or TwitterTimeLine in your app
- Open app on Android 6 or earlier
- Share a tweet (press share icon)
Expected behaviour Twitter app intent chooser to share the tweet
Actual behaviour
App crashes:
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
Android API Version Android 6 and prior
This can easily by adding the FLAG_ACTIVITY_NEW_TASK to the intents defined here: https://github.com/twitter/twitter-kit-android/blob/c148862c612c66d0f2b50cac40adf4e3d287cb8b/tweet-ui/src/main/java/com/twitter/sdk/android/tweetui/AbstractTweetView.java#L248
https://github.com/twitter/twitter-kit-android/blob/c148862c612c66d0f2b50cac40adf4e3d287cb8b/tweet-ui/src/main/java/com/twitter/sdk/android/tweetui/ShareTweetAction.java#L51
I have created a PR which resolves this issue: https://github.com/twitter/twitter-kit-android/pull/131
To reproduce you can use
context.getApplicationContext()
instead of context
when creating the intent. This mimics the same behaviour as reactContext.
Please review my pull request. In our application we have about 50.000 Android users with Android 6 or lower. We really need this fix.
@efrohnhoefer Any progress on this? As I've said, we have a lot of users affected by this bug.
Just do this:
- create a folder in your project
- put the *.aar files of the twitter project in there
- add "implementation fileTree(dir: '<your_folder_here>', include: ['*.aar'])" to your build.gradle
works like charm, and fixes your problem until they decide to implement/use your fix.