Android 解决极光推送点击通知栏消息APP会重启的问题
初衷:看了网上蛮多文档都提到了设置Intent.FLAG_ACTIVITY_NEW_TASK
,但这只是解决了能新建Activity跳转指定页面,尝试点击返回,之前的Activity就会被重置,也就是感觉APP重启了一下的感觉,于是还是要想办法解决这种差的体验。
后面浏览了极光社区,看到官方回复了这么一段话(其他的不用看,也没用)
那就可以推测也就是在点击通知栏的消息的时候,系统自动调用了clear之前的activity,于是索性来到receiver,把当点击通知栏消息的父级调用注释掉,没想到就成功了。
public class JPushReceiver extends JPushMessageReceiver {
@Override
public void onNotifyMessageArrived(Context context, NotificationMessage notificationMessage) {
super.onNotifyMessageArrived(context, notificationMessage);
}
@Override
public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) {
// 防止极光推送默认重启APP
/*super.onNotifyMessageOpened(context, notificationMessage);*/
// 自己的逻辑,跳转指定页面
...
}
}
主要就是注释掉这段方法即可
super.onNotifyMessageOpened(context, notificationMessage);
这样我们就实现了,即便正在使用APP浏览某个页面,收到通知点击了以后,返回来也保持状态的体验。