当启动页intent中有要跳转的uri时,执行过后,退出app,再次从历史堆栈打开app,这时,intent中的uri依旧存在,仍然会重复执行通过uri打开intent的过程。解决办法:
可以通过检查标志 FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY 来检查您的意图是否是由于从最近列表中启动的应用程序而发送的
if ((getIntent().getData() != null) && ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0)) {
//Handle the url passed through the intent
} else {
//proceed as normal,必要时可以清空uri
getIntent.setData(null);
}
附kotlin 扩展函数
fun Intent.isLaunchFromHistory(): Boolean = this.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY == Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY