Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve PendingIntent.getActivity()

I am trying to make a custom notification and cannot resolve this.

public void remNotifyClicked (View view){
    notification.setSmallIcon(R.drawable.ic_launcher);
    notification.setTicker("Ticker");
    notification.setContentTitle("Notification");
    notification.setContentText("Congratulation!");
    notification.setWhen(System.currentTimeMillis());


    Intent i = new Intent(this, SecondActivity.class);
    notification.setContentIntent( new PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));

    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(uniqueId, notification.build());

}

The problem here is, "getActivity" is showing as error(red colored) and it says it cannot resolve the symbol(when hovered over it). Thanks.

PS: I use Android Studio.

like image 903
Yashwanth Remidi Avatar asked Feb 22 '15 13:02

Yashwanth Remidi


People also ask

What is pending intent mutability?

A PendingIntent object wraps the functionality of an Intent object while allowing your app to specify something that another app should do, on your app's behalf, in response to a future action. For example, the wrapped intent might be invoked when an alarm goes off, or when the user taps on a notification.

What is PendingIntent Flag_update_current?

Setting PendingIntent. FLAG_UPDATE_CURRENT : Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent.


1 Answers

Replace

notification.setContentIntent( new PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));

with

notification.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));

getActivity() is a static method of the class PendingIntent and does not require an instance of PendingIntent in order to be invoked.

Try this. This will work.

like image 169
Y.S Avatar answered Oct 29 '22 00:10

Y.S