Я хочу разрешить удаление моего уведомления в активности, которая открывается после нажатия на нее в панели уведомлений.Я использую следующий код:
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);
И мой test.java выглядит так:
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);
}
});
}
}
Но приложение неожиданно закрывается.Кто-нибудь может мне помочь в этом?Спасибо !!