0

我创造了一个NotificationActivity(例如text.class),当主动说和我Click on it,还给我在页面(text.class)在此页面中我有一个TimerTask,我需要的是,当Click on that Notification Reset pageFinish() the TimerTask点击通知,然后完成TimerTask?

我该怎么做?

我以为当我click on notificationreset 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

添加FLAG_ACTIVITY_SINGLE_TOP标志为notifintent意图传递到运行有额外的键这表明意图是从Notification活动?如果是,则取消已运行TimerTask in onNewIntent

@Override 
public void onNewIntent(Intent intent){ 
    Bundle extras = intent.getExtras(); 
    if(extras != null) 
     if(extras.containsKey("isfromnotification")) 
     { 
      //cancel TimerTask here 
     } 
    }