问题描述
什么是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()
从文档:
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:
这篇关于sendBroadscast VS startActivity。区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!