twitter-kit-android icon indicating copy to clipboard operation
twitter-kit-android copied to clipboard

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag

Open Sammekl opened this issue 6 years ago • 3 comments

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

  1. Implement TwitterTweet or TwitterTimeLine in your app
  2. Open app on Android 6 or earlier
  3. 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

Sammekl avatar May 28 '18 13:05 Sammekl

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.

Sammekl avatar May 29 '18 12:05 Sammekl

@efrohnhoefer Any progress on this? As I've said, we have a lot of users affected by this bug.

Sammekl avatar Jun 07 '18 06:06 Sammekl

Just do this:

  1. create a folder in your project
  2. put the *.aar files of the twitter project in there
  3. 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.

MetallLogic93 avatar Oct 19 '18 20:10 MetallLogic93