Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

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

Open
Sammekl opened this issue May 28, 2018 · 3 comments

Comments

@Sammekl
Copy link

Sammekl commented May 28, 2018

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
Copy link
Author

Sammekl commented May 29, 2018

I have created a PR which resolves this issue: #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
Copy link
Author

Sammekl commented Jun 7, 2018

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

@MetallLogic93
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants