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