7

Running my app on the new Android KitKat device (API 19, 4.4) I get "Copied to Clipboard" everytime I try to create an Intent chooser. This is happening on Youtube, Tumblr and various other apps on Android KitKat. Looking at the logs I'm seeing the following exception:

com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@4150aac8

This used to be an issue caused when a device didn't have multiple apps to Intent to (see Why does Intent.createChooser() need a BroadcastReceiver and how to implement?). However, this is not the case on my device. Seems like something is broken in Android API 19.

Community
  • 1
  • 1
b.lyte
  • 6,518
  • 4
  • 40
  • 51
  • Discussion related to this bug: http://android.stackexchange.com/questions/42057/how-do-you-clear-share-actions-bound-to-copy-to-clipboard and http://www.reddit.com/r/Android/comments/1rcnow/did_the_default_behavior_of_share_change_in/. Also, there's a bug report here that you can star: https://code.google.com/p/android/issues/detail?id=61937 – halr9000 Dec 03 '13 at 20:55

2 Answers2

7

Here's my workaround solution for this issue. I first detect if the device is running on KIT_KAT or higher, and instead of creating a chooser, I simply try to start the intent. This will cause Android to ask the user which application they want to complete the action with (unless the user already has a default for all ACTION_SEND intents.

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setType("text/plain");

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    // This will open the "Complete action with" dialog if the user doesn't have a default app set.
    context.startActivity(sendIntent);
} else {
    context.startActivity(Intent.createChooser(sendIntent, "Share Via"));
}
b.lyte
  • 6,518
  • 4
  • 40
  • 51
0

@clu Has the answer right, just backwards lol. It should be this:

//Create the intent to share and set extras
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setType("text/plain");

//Check if device API is LESS than KitKat
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT)
    context.startActivity(sendIntent);
else
    context.startActivity(Intent.createChooser(sendIntent, "Share"));

This build check can be shortened to a one-liner as well:

//Create the intent to share and set extras
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setType("text/plain");

//Check if device API is LESS than KitKat
startActivity(Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ? sendIntent : intent.createChooser(sendIntent, "Share"));
Tyler
  • 11
  • 5