Aminadav Glickshtein
Aminadav Glickshtein

Reputation: 24600

sendBroadscast VS startActivity. What is the difference?

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);

Upvotes: 3

Views: 2804

Answers (1)

A--C
A--C

Reputation: 36449

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.

Upvotes: 2

Related Questions