Note that there are some explanatory texts on larger screens.

plurals
  1. POStart a new activity on notification icon click
    primarykey
    data
    text
    <p>I can already show an icon in the notification bar, as shown in the code below. I want to start a new activity (<code>myclass</code>) when the user clicks this icon, but I don't know how to do this. Where should I place the intent?</p> <pre><code>public class NotificationActivity extends Activity { AlarmManager am; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_notification); am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); setRepeatingAlarm(); } public void setRepeatingAlarm() { Intent intent = new Intent(this, TimeAlarm.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (20 * 1000), pendingIntent); System.out.println("Calling Alaram..."); } } public class BootUpReciever extends BroadcastReceiver { NotificationManager nm; @Override public void onReceive(Context context, Intent intent) { System.out.println("in broad...."); nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); CharSequence from = "Lokesh"; CharSequence message = "Notification Test..."; PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); Notification notif = new Notification(R.drawable.cherry_icon, "Notification Test...", System.currentTimeMillis()); notif.setLatestEventInfo(context, from, message, contentIntent); nm.notify(1, notif); if ((intent.getAction() != null) &amp;&amp; (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))) { System.out.println("in broadcast receiver....."); Intent i = new Intent(context, MainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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