Android 单击通知,然后完成时间任务?
我正在一个Android 单击通知,然后完成时间任务?,android,timer,android-notifications,android-pendingintent,Android,Timer,Android Notifications,Android Pendingintent,我正在一个活动中创建通知(例如text.class),当激活该活动时,我单击它,它会在该页面中返回我(text.class)在该页面中,我有一个TimerTask,当单击该通知重置页面时,我需要它计时器任务 我怎么能做到 我想当我点击通知时,重置页面和完成时间任务 这是我的通知: NotificationManager nman; nman=(NotificationManager) getSystemService(NOTIFICATION_SERVICE); Long when=System
活动中创建通知(例如text.class
),当激活该活动时,我单击它,它会在该页面中返回我(text.class
)在该页面中,我有一个TimerTask
,当单击该通知重置页面时,我需要它计时器任务
我怎么能做到
我想当我点击通知
时,重置页面
和完成时间任务
这是我的通知
:
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);
将FLAG\u ACTIVITY\u SINGLE\u TOP
标志添加到notificontent
中,并使用额外的键向正在运行的活动传递意图,该键指示来自通知的意图?如果是,则取消已在onNewIntent
中运行的TimerTask
:
@Override
public void onNewIntent(Intent intent){
Bundle extras = intent.getExtras();
if(extras != null)
if(extras.containsKey("isfromnotification"))
{
//cancel TimerTask here
}
}