What is the real use of onNewIntent()
in the activity life cycle and how do we use this method?
onNewIntent()在活动生命周期中的真正用途是什么?我们如何使用这种方法?
3 个解决方案
#1
39
This is called for activities that set launchMode to "singleTop" in their package, or if a client used the FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent).
这被称为在其包中将launchMode设置为“singleTop”的活动,或者在调用startActivity(Intent)时客户端使用FLAG_ACTIVITY_SINGLE_TOP标志。
If you set to single top, the activity will not be launched if it is already running at the top of the history stack. It will not relaunch just show from stack.
如果设置为单个顶部,则如果活动已在历史堆栈的顶部运行,则不会启动该活动。它不会重新启动只是从堆栈显示。
#2
25
Check this link onNewIntent();
检查此链接onNewIntent();
In manifest.xml, in an activity tag set launchmode="singleTask"
在manifest.xml中,在活动标记集中设置launchmode =“singleTask”
#3
3
Above answers are incomplete.
以上答案不完整。
In case the activity 'a1' of Application 'A1' has launch mode "singleTask" or "singleTop" and is already alive (in task t1) but paused, and now another task (say Task t2) (usually another android app) sends an intent to activity a1 of application A1, then instead of creating another instance of activity in task t2, android resumes a1 from task t1, by issuing a callback to onNewIntent(intent) method in a1.
如果应用程序'A1'的活动'a1'具有启动模式“singleTask”或“singleTop”并且已经存在(在任务t1中)但暂停,现在另一个任务(比如任务t2)(通常是另一个Android应用程序)发送意图活动应用程序A1的a1,然后通过在a1中发出对onNewIntent(intent)方法的回调,而不是在任务t2中创建另一个活动实例,android从任务t1恢复a1。
Tasks and back stack is an important concept, no blog explains better than android documentation itself.
任务和后台堆栈是一个重要的概念,没有博客解释比Android文档本身更好。
#1
39
This is called for activities that set launchMode to "singleTop" in their package, or if a client used the FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent).
这被称为在其包中将launchMode设置为“singleTop”的活动,或者在调用startActivity(Intent)时客户端使用FLAG_ACTIVITY_SINGLE_TOP标志。
If you set to single top, the activity will not be launched if it is already running at the top of the history stack. It will not relaunch just show from stack.
如果设置为单个顶部,则如果活动已在历史堆栈的顶部运行,则不会启动该活动。它不会重新启动只是从堆栈显示。
#2
25
Check this link onNewIntent();
检查此链接onNewIntent();
In manifest.xml, in an activity tag set launchmode="singleTask"
在manifest.xml中,在活动标记集中设置launchmode =“singleTask”
#3
3
Above answers are incomplete.
以上答案不完整。
In case the activity 'a1' of Application 'A1' has launch mode "singleTask" or "singleTop" and is already alive (in task t1) but paused, and now another task (say Task t2) (usually another android app) sends an intent to activity a1 of application A1, then instead of creating another instance of activity in task t2, android resumes a1 from task t1, by issuing a callback to onNewIntent(intent) method in a1.
如果应用程序'A1'的活动'a1'具有启动模式“singleTask”或“singleTop”并且已经存在(在任务t1中)但暂停,现在另一个任务(比如任务t2)(通常是另一个Android应用程序)发送意图活动应用程序A1的a1,然后通过在a1中发出对onNewIntent(intent)方法的回调,而不是在任务t2中创建另一个活动实例,android从任务t1恢复a1。
Tasks and back stack is an important concept, no blog explains better than android documentation itself.
任务和后台堆栈是一个重要的概念,没有博客解释比Android文档本身更好。