简体   繁体   English

启动配置活动时调用onUpdate

[英]onUpdate called when Configuration Activity is launched

According to the App Widgets documentation, onUpdate method should not be called if a Configuration Activity has been declared. 根据App Widgets文档,如果已声明配置活动,则不应调用onUpdate方法。

Still it is being called when the configuration activity is launched... 启动配置活动时仍会调用它...

How do I prevent it from being called and call it only when the configuration activity has been closed with RESULT_OK code. 如何防止调用它,并且仅当使用RESULT_OK代码关闭配置活动时才调用它。

Thank you upfront. 预先感谢您。

I'm never too certain about what methods are called on you AppWidget, because some of the logic is up to the developer of the launcher application, not to the Android OS itself. 对于您在AppWidget上调用的方法,我永远不会太确定,因为某些逻辑取决于启动器应用程序的开发人员,而不取决于Android OS本身。 So this differs quite a lot between Launchers (Samsung, Google, HTC, KK etc.) Your widget should be prepared to degrade in a way acceptable for the user. 因此,启动器(三星,谷歌,HTC,KK等)之间有很大的不同。您的小部件应准备好以用户可以接受的方式降级。

Take a look at AppWidgetProvider source: 看一下AppWidgetProvider的源代码:

https://android.googlesource.com/platform/frameworks/base.git/+/android-cts-4.2_r1/core/java/android/appwidget/AppWidgetProvider.java https://android.googlesource.com/platform/frameworks/base.git/+/android-cts-4.2_r1/core/java/android/appwidget/AppWidgetProvider.java

It extends BroadcastReceiver, so you can add extra logic to onReceive() to avoid calling onUpdate() if your configuration activity hasn't been closed yet. 它扩展了BroadcastReceiver,因此,如果尚未关闭配置活动,则可以向onReceive()添加额外的逻辑以避免调用onUpdate()。

You can use SharedPreferences to pass this information. 您可以使用SharedPreferences传递此信息。

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

相关问题 仅在应用程序启动时显示启动画面,而不是每次调用包含启动画面代码的活动时显示启动画面 - Display splash screen only when the app is launched and not every time when the activity containing splash screen code, is called 启动应用程序时发生的活动 - Activity that happens when the app is launched Android Activity在启动时崩溃 - Android Activity crashing when launched 未启动活动时是否可以运行 java 代码? - Is it possible to run java code when activity is not launched? 当“扩展”扩展ListView的活动时,应用程序崩溃 - Application Crashes when an Activity that Extends ListView is 'Launched' 在Android中启动活动时如何显示值 - How to show values when the activity is launched in android Android SearchView 既未启动可搜索活动,也未调用 onNewIntent() - Android SearchView neither searchable activity launched nor onNewIntent () called Intellij IDEA:启动运行配置时得到通知 - Intellij IDEA: Get notified when a Run Configuration is launched 从Jenkins启动时配置参数sonar.java.libraries - Configuration of parameter sonar.java.libraries when launched from Jenkins 当我关闭启动它的活动时,Android Service死亡 - Android Service dies in when I close the Activity that launched it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM