在Android的API 19(4.4)的intent.createChooser方法导致IntentServiceLeak [英] On Android API 19 (4.4) the intent.createChooser method causes IntentServiceLeak

查看:149
本文介绍了在Android的API 19(4.4)的intent.createChooser方法导致IntentServiceLeak的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的运行全新的Andr​​oid奇巧设备上的应用程序(API 19 4.4),我得到复制到剪贴板每次我试图创建一个Intent选择器。这是发生在Youtube,和的tumblr在Android奇巧各种其他应用程序。纵观日志我看到以下异常:

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渗漏IntentReceiver com.android.internal.app.ResolverActivity$1@4150aac8

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

这曾经是一个问题引起的,当一个设备没有多个应用程序,以意图(见<一href="http://stackoverflow.com/questions/10068954/why-does-intent-createchooser-need-a-broadcastreceiver-and-how-to-implement">Why确实Intent.createChooser()需要一个BroadcastReceiver,以及如何实现?)。然而,这不是我的设备上的情况。似乎就象是在Android的API 19被打破。

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.

推荐答案

下面是我对这个问题的解决方法解决方案。我第一次检测,如果该设备上KIT_KAT或更高的运行,并且,而不是创建一个选择器,我只是尝试启动的意图。这将导致Android的要求,他们要完成的动作(除非用户已经有一个默认为所有ACTION_SEND意图这些应用程序的用户。

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"));
}

这篇关于在Android的API 19(4.4)的intent.createChooser方法导致IntentServiceLeak的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆