简体   繁体   English

Android onNewIntent同步

[英]android onNewIntent Synchronization

In my app I have a MainActivity and a Service . 在我的应用程序中,我有一个MainActivity和一个Service I started my APP. 我启动了我的APP。 Then I put it to background. 然后我把它放在后台。 I opened a ES file explorer, select a file, and click to open with my APP. 我打开了一个ES文件浏览器,选择了一个文件,然后单击以使用我的APP打开。

In my APP, I implemented onNewIntent() to handle intent from ES file explorer. 在我的APP中,我实现了onNewIntent()来处理来自ES文件浏览器的意图。 In onNewIntent() , I broadcase the file name to service. onNewIntent() ,我将要服务的文件名onNewIntent()了。

The observation is (by putting log message in onCreate() , onNewIntent() , onStartCommand() ): 观察是(通过将日志消息放入onCreate()onNewIntent()onStartCommand() ):

The activity is restarted. 活动已重新启动。 I see onCreate() is called. 我看到onCreate()被调用了。

In onCreate() I started the Service . onCreate()我启动了Service

I then see the called of onNewIntent() . 然后,我看到了onNewIntent()的调用。

However, the service does not start up fast enough to handle the intent of onNewIntent() , so I did not get the filename. 但是,该服务的启动速度不足以处理onNewIntent()的意图,因此我没有得到文件名。

What is wrong with my logic? 我的逻辑有什么问题? or what is the correct way to do so? 或正确的方法是什么?

have u set this in android manifest 你在Android清单中设置了吗

android:launchMode="singleTop"

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标志的活动,将调用此方法。 In either case, when the activity is re-launched while at the top of the activity stack instead of a new instance of the activity being started, onNewIntent() will be called on the existing instance with the Intent that was used to re-launch it. 在这两种情况下,当在活动堆栈的顶部重新启动活动而不是启动活动的新实例时,将使用已用于重新启动的Intent在现有实例上调用onNewIntent()它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM