sendBroadscast VS startActivity。区别是什么? [英] sendBroadscast VS startActivity. What is the difference?

查看:126
本文介绍了sendBroadscast VS startActivity。区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是sendBroadcast(意向)给startActivity(意向)。

之间的型动物

为什么这不工作:

 意图smsIntent =新的意图(Intent.ACTION_SENDTO);
smsIntent.setData(Uri.parse(手机短信:0533));
smsIntent.putExtra(sms_body,的SMS文本);
sendBroadcast(smsIntent);
 

解决方案

<一个href="http://developer.android.com/reference/android/content/Context.html#sendBroadcast%28android.content.Intent%29"相对=nofollow> sendBroadCast() 发送一个全球直播是要被任何 BroadcastReceivers 被设置为接收广播。

<一个href="http://developer.android.com/reference/android/content/Context.html#startActivity%28android.content.Intent%29"相对=nofollow> startActivity() 试图根据任你指定类名来启动活动的意图行动(这是一个字符串)。

在你的情况 Intent.ACTION_SENDTO 是一个Intent动作等等,需要 startActivity()

从文档:

  

标准活动操作

     

这些是目前的标准行动,意图定义   发射活动(通常是通过 startActivity(意向)。最   重要的,并且是迄今为止最经常使用的,是ACTION_MAIN和   ACTION_EDIT。

What is the differents between sendBroadcast (intent) to startActivity(intent).

Why this don't work:

Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.setData( Uri.parse( "sms:0533"));
smsIntent.putExtra("sms_body", "The SMS text");
sendBroadcast(smsIntent);

解决方案

sendBroadCast() sends a global broadcast that is to be picked up by any BroadcastReceivers that are set to receive that broadcast.

startActivity() attempts to start an Activity based on either the class name you specify or the Intent Action (which is a String).

In your case Intent.ACTION_SENDTO is an Intent Action and so, needs startActivity()

From the docs:

Standard Activity Actions

These are the current standard actions that Intent defines for launching activities (usually through startActivity(Intent). The most important, and by far most frequently used, are ACTION_MAIN and ACTION_EDIT.

这篇关于sendBroadscast VS startActivity。区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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