【问题标题】:Activity opened from Status bar not getting finished从状态栏打开的活动未完成
【发布时间】:2012-11-05 17:46:12
【问题描述】:

我创建了一个状态栏通知,它会在状态栏上给我一些消息,单击该消息会重定向到一个全新的布局。 状态条码 -

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);

此布局有一个名为 Complete on click 的按钮,我正在删除数据库中的一行并调用 finish()。代码 -

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

在此之后,如果我从普通菜单打开我的应用程序,它仍然会显示相同的布局,其中包含完整的按钮,而不是我的登陆活动。为什么这个活动没有完成?

提前致谢, 考希克

【问题讨论】:

  • 您可能需要发布更多代码。仅从这两个陈述很难看出发生了什么。
  • 请看一下,如果需要更多详细信息,请告诉我

标签: android android-intent android-notifications


【解决方案1】:

我建议您在线查看 Notifications API 指南的最新更新。人们有时会对启动 Activity 以处理 Notification 时发生的事情感到惊讶。指南中描述了您应该使用的选项。

一个相当简单的总结是,一个由 Notification 启动的 Activity 应该是一个单独的任务。如果 Activity 是应用程序的正常部分,那么用户应该使用“最近”来访问从通知启动的任务。如果 Activity 仅用于通知,则任务应在用户离开后完成。

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

在您的情况下,我很确定您开始的新 Activity 已被 TaskAffinity “卡住”到您的应用程序中。 API 指南将向您展示如何解决这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-25
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多