当前位置: 代码迷 >> Android >> android 使用notification activity间切换的有关问题
  详细解决方案

android 使用notification activity间切换的有关问题

热度:65   发布时间:2016-05-01 21:09:07.0
android 使用notification activity间切换的问题
我做了一个notification通知栏的demo,主要的流程是activity A点击按钮,发送通知,A退出,点击通知栏,弹出activity B(主题为窗口式的),点击B中的确定按钮,重新打开activity A,点击取消按钮,B消失。

现在有个问题纠结了一整天了,当发送通知栏后点击该通知栏,弹出B,点取消按钮,把B窗口finish掉,然后点最近打开程序里的这个程序,首先出来的是B这个窗口而不是A这个主activity。我想这里可能涉及到堆栈之类的问题,我不太懂,请这方面的高手帮忙解答下,只要窗口B关闭后不再首先打开就好。
以下是我发送通知的代码:
 public void showNotification(int icon,String tickertext,String title,String content){
 
   
  Notification notification=new Notification(icon,tickertext,System.currentTimeMillis());
 
  notification.flags = Notification.FLAG_AUTO_CANCEL;
  //Intent调转到窗口B
  Intent i =new Intent(this,ActivityDialog.class);
  i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  PendingIntent pt=PendingIntent.getActivity(this, 0, i, 0);
 
  notification.setLatestEventInfo(this,title,content,pt);
  nm.notify(notification_id, notification);
 
  }

------解决方案--------------------
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent pt=PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

加上去试试

不明白为啥LZ要做成这样子,直接打开A就行了,既然用户点了,就说明他有打开的需求
------解决方案--------------------
我怎么感觉你说的B关闭后,主程序貌似没onDestory,
当你在最近列表中再点击的时候是onResume,而不是onCreate
  相关解决方案