How to post a tweet using the official Twitter application, using intention, and then returning to your application?

I use this code to start posting to twitter using the official Twitter app:

Intent twitterIntent = new Intent(Intent.ACTION_VIEW); //Intent.ACTION_VIEW twitterIntent.setAction("android.intent.action.SEND"); twitterIntent.setFlags(0x3000000); twitterIntent.setType("text/plain"); twitterIntent.setClassName("com.twitter.android", "com.twitter.android.PostActivity"); twitterIntent.putExtra(Intent.EXTRA_TEXT, ("Random post")); startActivity(twitterIntent); 

I also check if this intent is available before using it with:

 public static boolean canReceiveIntent (Intent intent, Context c) { PackageManager packageManager = c.getPackageManager(); List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0); boolean isIntentSafe = activities.size() > 0; return isIntentSafe; } 

It works fine, but the Twitter application remains open after the tweet is posted (via the channel). I also tried using startActivityForresult (), but it fails with an error:

 java.lang.RuntimeException: android.util.AndroidRuntimeException: FORWARD_RESULT_FLAG used while also requesting a result 

How to return to my application after posting a tweet?

+4
source share
1 answer

The IMO official Twitter application does not follow the Android Intent life cycle, terminating itself after the ACTION_VIEW or ACTION_SEND Intent is received via a call to the startActivityForResult method, but it remains open and violates the experience for any applications that send such intentions to it.

0
source

Source: https://habr.com/ru/post/1445473/


All Articles