How to open current activity with android notification?

Android how to intent activity when notification is pressed

  • How can I intent the activity after clicking the image on notification bar? How can I make intent? Thanks. public class AlarmService extends BroadcastReceiver { NotificationManager nm; @Override public void onReceive(Context context, Intent intent) { nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); CharSequence from = "Check your fridge"; CharSequence message = "It's time to eat!"; PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); Notification notif = new Notification(R.drawable.fridge_icon3, "Keep Fridge", System.currentTimeMillis()); notif.setLatestEventInfo(context, from, message, contentIntent); notif.defaults |= Notification.DEFAULT_SOUND; notif.flags |= Notification.FLAG_AUTO_CANCEL; nm.notify(1, notif); } }

  • Answer:

    The code you have posted already has an intent in it e.g. you have new Intent() in the contentIntent. It is not much use as you have not filled it in with anything. You need somthing like this. Intent notificationIntent = new Intent(this, MyAvtivity.class); // modify the intent as nessasary here. PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); User Guide http://developer.android.com/guide/topics/ui/notifiers/notifications.html

wholee1 at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.