我正在打开有关单击通知的活动。但是,如果该活动已经打开,那么我想重新打开该活动。从重新开放开始我的意思是;关闭该活动,然后再次打开它以显示更新的数据。为此,我将这行代码添加到通知的意图中:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
但是问题是,当我单击/点击通知时,整个应用程序都关闭了,而不是仅完成该活动。所以请帮忙。
您可以检查是否Activity
已打开。我是这样做的
public static boolean FLAG=false;
在onCreate
做true
@Override
protected void onCreate(Bundle savedInstanceState) {
FLAG=true;
.
.
}
现在您可以在Notification
类中检查此变量的值。
boolean isOpen=YourActivty.FLAG;
if(isOpen){
//just clear the notification with adding the notification's data in the activity if you are sending to any listview or so.
//for adding the data to listview you need to make the `ArrayList`(i assume) and make a method in the adapter that will notify the adapter.
}else{
//call the Activity
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句