Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm going to show you how to <a href="http://developer.android.com/training/sharing/send.html" rel="nofollow">send and receive implicit intents</a>. This is useful for sending data to one or many activities, services or broadcast receivers and also between apps. The downside is that it is a 'public' intent (if you do not use the LocalBroadcastManager) so don't send any sensitive information.</p> <ol> <li>Create a send-method that the sender uses.</li> <li>Modify the AndroidManifest.xml for the receiving entity (In your case an Activity)</li> <li>Modify the receiving entity to handle the incoming Intent.</li> </ol> <p>Step one - Create a send-method that the sender uses.:</p> <pre><code>public final static String ACTION_SEND_NAME = "com.example.intent.action.SEND_NAME"; public final static String ACTION_SEND_NAME_EXTRA = "name"; public static void sendPackageName(Context context, String name) { if (null == context || null == name) { throw new IllegalArgumentException("Argument(s) may not be null"); } Intent intent = new Intent(ACTION_SEND_NAME); intent.putExtra(ACTION_SEND_NAME_EXTRA, name); //You might add extra these flags intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP|FLAG_ACTIVITY_SINGLE_TOP); //LocalBroadcastManager.getInstance(context).sendBroadcast(intent); //context.sendBroadcast(intent); //context.startService(intent); context.startActivity(intent); } </code></pre> <p>Step two - Modify the AndroidManifest.xml:</p> <pre><code> &lt;activity android:name="com.example.MyActivity" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;!-- Other Intent filters --&gt; &lt;action android:name="com.example.intent.action.SEND_NAME" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; </code></pre> <p>Step three - Modify the receiving entity:</p> <pre><code>void onCreate (Bundle savedInstanceState) { //... // Get intent, action and MIME type Intent intent = getIntent(); String appName; if (ACTION_SEND_NAME.equals(intent.getAction())) { appName = intent.getStringExtra(Intent.ACTION_SEND_NAME_EXTRA); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload