English 中文(简体)
为什么需要一个广播接收器,以及如何实施?
原标题:Why does Intent.createChooser() need a BroadcastReceiver and how to implement?

下面几页,从我执行<代码>onOptionsItemS selected()时起,用电子邮件地址、主题和填满前的机把用户从我的手表带至邮件客户。 我用这一简单方式让用户给我反馈。

String uriText =
    "mailto:" + emailAddress +
    "?subject=" + subject +
    "&body=" + body;

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uriText));
startActivity(Intent.createChooser(emailIntent, "Pick an email app:"));

当邮件收发时(关于我的Nexus S with 4.0.4),LogCat产出如下,我可以说明为什么;谷歌和SO搜索createChooser undgisterReceiver似乎没有结果,我可以找到许多实例createChooser (),这些例子也称作unregisterReceiver ()。

04-08 21:26:19.094:E/ActectiveThread(27894): Activities com.android.internal.app.ChooserActative has 漏掉了原先在此登记的IntentReceiver com.android.internal.app.ResolverActative$1@4150aac8。 难道你没有向未出庭者发出呼吁吗?

04-08 21:26:19.094:E/ActativeThread(27894):android.app. IntentReceiverLeaked: Activities com.android.internal.app.ChooserActative has 漏掉了原先在此登记的IntentReceiver com.android.internal.app.ResolverActative$1@4150aac8。 难道你没有向未出庭者发出呼吁吗?

04-08 21:26:19.094:E/ActativeThread(27894): at android.app.LoadedApk$ReceiverDissigner. (LoadedApk.java:763)

This feels like an Android bug because my own code doesn t call registerReceiver(), so why is Android complaining that I need to call unregisterReceiver()?

最佳回答

我在银河Nexus和4.0.4处也看到这一点,但只有只有一个选择,选择者没有。

这是一种陈词滥调,不是你可以做的事。 他们的决心是注册广播员,但总是没有注册。

详细情况:

启动行动。 在Create(Create),该项活动称为“活动”。

mPackageMonitor.register(this, false);

mPackage Monitor是一家广播接收器,在register()内注册。 通常,接收人未在<条码>上登记。 然而,后来在<代码>onCreate(>)中,该编码检查了用户可以选择的多少选择。 如果只有一个电话:finish()。 由于finish()在onCreate(>中被称作,其他生命周期方法从未被称作,而直线跳到onDestroy(<>-泄漏接收人。

我在安的问答数据库中看到了这方面的ug,因此,I

欲了解更多情况,请在法典中看到这一点:

作为附带说明,谷歌利用电子邮件作为你不想使用选择者的例子,因此你可能认为只是通常发射意图。 See the javadocs for Intent#ACTION_CHOOSER

问题回答

简单解决问题。

More info here: https://developer.android.com/training/basics/intents/sending.html

Uri location = Uri.parse("geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+California");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);

PackageManager pkManager = getPackageManager();
List<ResolveInfo> activities = pkManager.queryIntentActivities(mapIntent, 0);

if (activities.size() > 1) {
    // Create and start the chooser
    Intent chooser = Intent.createChooser(mapIntent, "Open with");
    startActivity(chooser);

  } else {
    startActivity( mapIntent );
}




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签