2

I'm opening the send menu from a button click in a particular activity:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_TEXT, "meh");
try {
    startActivity(Intent.createChooser(i, "pfft"));
} ...

Works fine, but when hitting "Back" to close it, logcat says

Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@405ab288 that was originally registered here. Are you missing a call to unregisterReceiver()?

Nothing else happens - the app continues to run without a problem.

Searching says that apparently the above code has registered a BroadcaseReceiver and it needs to be unregistered (via unregisterReceiver), probably during onResume (or onPause). The signature for unregister receiver says the single argument should be a BroadcastReceiver instance (makes sense).

My question is - where is the reference to the BroadcastReceiver? AFAICT the methods used to open the menu don't return a BroadcastReceiver - how do I find and reference the appropriate one to unregister it?

TYIA

(should note that I'm debuging on a Samsung Galaxy SII, and this thread indicates it might be a device-specific bug?)

Community
  • 1
  • 1
momo
  • 3,885
  • 4
  • 33
  • 54

1 Answers1

0

Apparently this is a bug in Android with certain devices. See this report: http://code.google.com/p/android/issues/detail?id=29399. It looks like it's only a problem when you use a chooser and there is only one option to choose from.

If you call Intent.createChooser(), it will leak a BroadcastReceiver if there's only possible option.

Based on the current source, the problem appears to be that ResolverActivity is registering the receiver in onCreate(), but then calling finish() if there's only one option. This causes the code to skip onStop(), which is where the receiver is unregistered.

Community
  • 1
  • 1
Christian
  • 1,830
  • 15
  • 26