2012-11-05 16 views
0

我已经创建了一个状态栏通知,该状态栏通知在状态栏上给了我一些消息,当点击该消息重定向到全新的布局时。 状态栏的代码 -从状态栏打开的活动没有完成

NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
     Intent notificationIntent = new Intent(this, TaskCompleteActivity.class); 
     notificationIntent.putExtra(TasksDBAdapter.KEY_ROWID, rowId); 
     notificationIntent.putExtra(TasksDBAdapter.KEY_TITLE, taskTitle); 
     notificationIntent.putExtra(TasksDBAdapter.KEY_BODY, taskDesc); 
     //notificationIntent.putExtra("NotificationId",); 

     Log.i(TAG,"rowId in doReminderWork" + rowId); 
     PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent,PendingIntent.FLAG_ONE_SHOT); 


     Notification note=new Notification(android.R.drawable.stat_sys_warning,taskDesc,System.currentTimeMillis());        
     note.setLatestEventInfo(this, taskTitle,taskDesc, pi); 
     note.defaults |= Notification.FLAG_AUTO_CANCEL; 
     note.defaults |= Notification.DEFAULT_SOUND; 
     note.defaults |= Notification.DEFAULT_VIBRATE; 
     // you need to clear the notification on click of status bar notification // 
     note.flags |= Notification.FLAG_NO_CLEAR;        
     // An issue could occur if user ever enters over 2,147,483,647 tasks. (Max int 
     // value). 
     // I highly doubt this will ever happen. But is good to note. 
     int id = (int)((long)rowId);            
     mgr.notify(id, note); 

这种布局是具有呼吁点击完成,其中我在数据库中的一行,并调用完成按钮()。代码 -

public void completeTask(){ 
     taskDBAdapter.deleteReminder(rowId); 
     this.finish(); 
    } 

在此之后,如果我从正常的菜单中打开我的应用程序,它仍然显示我有完整的按钮,而不是我的目标活动此相同的布局。为什么这个活动没有完成?

由于事先 考希克

+0

您可能需要发布一些更多的代码。从这两个陈述中很难看到发生了什么。 –

+0

请留下余地,让我知道是否需要更多的细节 – RayKaushik

回答

0

我建议你看看最近的通知API指南的在线更新。人们有时会惊讶于当他们启动一个活动来处理通知时会发生什么。指南中介绍了您应该使用的选项。

一个相当简单的总结是,由通知开始的活动应该是一个单独的任务。如果“活动”是应用程序的正常部分,则用户应使用“最近”来获取从通知开始的任务。如果“活动”仅用于通知,则应在用户离开时完成任务。

此模式保留了用户对用户体验的期望。

就你而言,我非常确定你开始的新Activity被TaskAffinity“卡住”到了你的应用程序中。 API指南将告诉你如何解决这个问题。

相关问题