单击Notification然后完成TimerTask?

时间:2014-09-21 07:00:46

标签: android timer android-notifications android-pendingintent

我正在Notification中创建Activity(例如text.class),当我和Click on it处于活动状态时,它会在该页面中返回text.class })在此页面中,我有一个TimerTask,我需要Click on that Notification Reset pageFinish() the TimerTask

我怎么做?

当我click on notification reset pagefinish 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);

1 个答案:

答案 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
        }
    }