Note that there are some explanatory texts on larger screens.

plurals
  1. POReceive signal after notification clicked
    primarykey
    data
    text
    <p>I fire a notification from <code>MainActivity</code> class. When user click the notification, i'd like to return back to <code>MainActivity</code> class and <strong>execute a method</strong>. I'd also like to know <strong>which notification is clicked</strong> (Assuming that i fire multiple notifications with different <code>id</code>). Here what i did and it didn't work</p> <p>Inside <code>MainActivity.class</code>:</p> <pre><code>private void showNotification(String title, String message, int id) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(title) .setContentText(message); Intent resultIntent = new Intent(this, MainActivity.class); resultIntent.setAction("mAction"); PendingIntent resultPendingIntent = PendingIntent.getBroadcast(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(id, mBuilder.build()); } </code></pre> <p>Same inside <code>MainActivity.class</code> i create a <code>BroadcastReceiver</code> class but <strong>it never got called</strong>:</p> <pre><code>public class MyBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if(action.equals("mAction")) { //execute my method here } } } </code></pre> <p>I did add <code>MyBroadcastReceiver.class</code> receiver in <code>AndroidManifest.xml</code>:</p> <pre><code>&lt;receiver android:name=".MyBroadcastReceiver" &gt; &lt;/receiver&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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