Note that there are some explanatory texts on larger screens.

plurals
  1. POdelete notification from android
    text
    copied!<p>I want to give option of deleting my notification in the activity which gets opened after clicking it from notification bar. I am using the following code:</p> <pre><code>nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Log.i(TAG, "after NotificationManager"); Intent intent = new Intent(this,test.class); intent.putExtra("title", title); intent.putExtra("subject", subject); intent.putExtra("notificationid", count); Log.i(TAG, title); Log.i(TAG, subject); PendingIntent pi = PendingIntent.getActivity(this, count, intent,0); Notification n = new Notification(R.drawable.icon,subject,System.currentTimeMillis()); n.setLatestEventInfo(this, title, subject, pi); n.defaults = Notification.DEFAULT_LIGHTS; nm.notify(count, n); </code></pre> <p>And my test.java looks like this:</p> <pre><code>public class test extends Activity { TextView Title; TextView Subject; Button Clear; protected int notificationid; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); String title=""; String subject=""; Bundle extras = getIntent().getExtras(); if(extras !=null) { title = extras.getString("title"); subject = extras.getString("subject"); notificationid = extras.getInt("notificationid"); } Title = (TextView) findViewById(R.id.Title); Subject = (TextView) findViewById(R.id.Subject); Title.setText(title); Subject.setText(subject); Clear.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { NotificationManager nm ; nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Log.i(getClass().getSimpleName(), " onClick inside test caled...."); nm.cancel(notificationid); } }); } } </code></pre> <p>But application is getting closed unexpectedly. Can anyone help me out in this? Thanks!!</p>
 

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