ChooserActivity has leaked IntentReceiver com.andr

2019-06-08 19:57发布

I'm trying to open a xml file with default application on the phone when clicking a button of my app. after google i found and followed this: http://www.androidsnippets.com/open-file-with-default-application-using-intents , my code is just as:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(_file), "application/*"); 
startActivity(intent);

it works on my phone, but the logcat got some errors:

01-07 02:42:48.242: E/ActivityThread(11280): Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@417ffc78 that was originally registered here. Are you missing a call to unregisterReceiver()?
01-07 02:42:48.242: E/ActivityThread(11280): android.app.IntentReceiverLeaked: Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@417ffc78 that was originally registered here. Are you missing a call to unregisterReceiver()?
01-07 02:42:48.242: E/ActivityThread(11280):    at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:763)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:567)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1055)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1042)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1036)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:341)
01-07 02:42:48.242: E/ActivityThread(11280):    at com.android.internal.content.PackageMonitor.register(PackageMonitor.java:65)
01-07 02:42:48.242: E/ActivityThread(11280):    at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:99)
01-07 02:42:48.242: E/ActivityThread(11280):    at com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:53)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.app.Activity.performCreate(Activity.java:4467)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1925)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1986)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.app.ActivityThread.access$600(ActivityThread.java:128)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1152)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.os.Looper.loop(Looper.java:137)
01-07 02:42:48.242: E/ActivityThread(11280):    at android.app.ActivityThread.main(ActivityThread.java:4449)
01-07 02:42:48.242: E/ActivityThread(11280):    at java.lang.reflect.Method.invokeNative(Native Method)
01-07 02:42:48.242: E/ActivityThread(11280):    at java.lang.reflect.Method.invoke(Method.java:511)
01-07 02:42:48.242: E/ActivityThread(11280):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
01-07 02:42:48.242: E/ActivityThread(11280):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
01-07 02:42:48.242: E/ActivityThread(11280):    at dalvik.system.NativeStart.main(Native Method)

I didn't register anything, and don't know how to fix that "Are you missing a call to unregisterReceiver()", how can i change my code?

1条回答
趁早两清
2楼-- · 2019-06-08 20:38

I'm not 100% sure but if it works fine AND throws the exception probably you need do nothing about it. It can be problem of your device, for example, error in customised by vendor Android OS. Try to test it on emulator, if it wouldn't throw an exception, just leave it as is. I think your code is fine.

查看更多
登录 后发表回答