android - 发送广播 VS 启动 Activity 。有什么不同?

标签 android

sendBroadcast (intent) 和 startActivity(intent) 有什么不同。

为什么这不起作用:

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

最佳答案

sendBroadCast()发送一个全局广播,该广播将被设置为接收该广播的任何 BroadcastReceivers 接收。

startActivity()尝试根据您指定的类名 Intent Action(它是一个字符串)启动一个 Activity。

在你的情况下 Intent.ACTION_SENDTO是一个 Intent Action,因此需要 startActivity()

来自文档:

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.

关于android - 发送广播 VS 启动 Activity 。有什么不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14184220/

相关文章:

android - 创建新应用或改进现有应用

android - 如何在 Mapbox 4.1 中添加自己的图 block

java - 更改 PopupWindow 中 TextView 的文本不起作用

android - Fabric 和 Ionic 集成

android - 在特定 Activity 打开后销毁所有以前的 Activity

android - 动画仅在第一次单击按钮时有效

java - 使用Facebook SDK 4在Android中加载Facebook个人资料图片时获取异常

android - 无法在Android中使用MediaPlayer播放MediaStore.Audio歌曲

Android 左侧快速滚动

android - 我可以在 LinearLayout 中强制缩小特定元素吗