我正在Notification
中创建Activity
(例如text.class
),当我和Click on it
处于活动状态时,它会在该页面中返回text.class
})在此页面中,我有一个TimerTask
,我需要Click on that Notification Reset page
或Finish() the TimerTask
。
我怎么做?
当我click on notification
reset page
和finish TimerTask
时我想到了。
这是我的Notification
:
NotificationManager nman;
nman=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Long when=System.currentTimeMillis();
Notification n;
n=new Notification(R.drawable.chat_logo,"",when);
Context context=getApplicationContext();
String Title=G.context.getResources().getString(R.string.StatusM);
String Text=G.context.getResources().getString(R.string.Statusms);
Intent notifintent=new Intent(context,ConversationPage.class);
PendingIntent pending;
pending=PendingIntent.getActivity(context,0,notifintent,android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
n.setLatestEventInfo(context, Title, Text, pending);
n.flags = Notification.FLAG_AUTO_CANCEL;
nman.notify(0,n);
答案 0 :(得分:1)
将FLAG_ACTIVITY_SINGLE_TOP
标记添加到notifintent
传递意图以运行具有额外密钥的活动,该密钥表示来自Notification
的意图?如果是,则取消已在TimerTask
中运行onNewIntent
:
@Override
public void onNewIntent(Intent intent){
Bundle extras = intent.getExtras();
if(extras != null)
if(extras.containsKey("isfromnotification"))
{
//cancel TimerTask here
}
}