4

我有下载正在进行的文件对话框的活动。当用户按下“隐藏”按钮时,活动会创建通知并隐藏进度对话框。当用户点击通知时,活动再次在活动中显示进度对话框。按下“返回”按钮后,如何将活动切换到返回任务?

4

2 回答 2

6

如果您不破坏活动,则必须将活动启动模式设置为single_instance并用于moveTaskToBack(true)发送到后台。

于 2013-10-22T23:36:15.850 回答
2

您需要做的是调用从堆栈finish()中删除。Activity然后在您的通知中,设置Activity单击它时要调用的名称,如下所示:

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
Notification notification = new Notification(R.drawable.icon,
  "A new notification", System.currentTimeMillis());
// Specify the called Activity
Intent intent = new Intent(this, YourActivityName.class);
intent.putBoolean("isDownloading", true); // check this value in Activity
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, "This is the title",
  "This is the text", activity);
notificationManager.notify(0, notification); 
于 2012-09-21T04:19:40.597 回答