sendBroadscast VS startActivity。区别是什么?区别、sendBroadscast、VS、startActivity

2023-09-08 00:20:50 作者:我历史不好别跟我提曾经

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

之间的型动物

为什么这不工作:

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

解决方案

sendBroadCast() 发送一个全球直播是要被任何 BroadcastReceivers 被设置为接收广播。

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.