简体   繁体   English

按下主键时从配置活动中更新小部件

[英]Updating widget from configuration activity when home key is pressed

I am developing a widget and I am using the android:configure setting in the widget provider xml to setup the widget when first added on the home screen. 我正在开发一个窗口小部件,并且在窗口小部件提供程序xml中使用android:configure设置来首次将其添加到主屏幕时对其进行设置。 The problem is that this only works if the user taps the back key from the configuration activity. 问题是,这仅在用户从配置活动中点击返回键时有效。 If the user taps the HOME key, the widget is not added. 如果用户点击HOME键,则不会添加小部件。 Is there a way to add the widget on the home screen even of the user taps the Home key? 有没有办法即使用户点击Home键也可以在主屏幕上添加小部件?

Thanks 谢谢

I have found a workaround which seems to do the trick. 我发现一种解决方法似乎可以解决问题。 Here is what to do: 这是做什么的:

Instead of specifying the configuration activity in the widget provider xml, specify a different activity, for example StartActivity. 而不是在小部件提供程序xml中指定配置活动,而是指定其他活动,例如StartActivity。

In the constructor of the StartActivity do the following: 在StartActivity的构造函数中,执行以下操作:

  • Send a broadcast intent with its result set to RESULT_OK back to the widget 将结果设置为RESULT_OK的广播意图发送回小部件
  • Start the configuration activity 开始配置活动
  • Call finish to stop the StartActivity 调用完成以停止StartActivity

In the onStop function of the configuration activity update the widget to reflect any changes that depend on any of the configuration settings. 在配置活动的onStop功能中,更新小部件以反映依赖于任何配置设置的任何更改。

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

相关问题 按下Home键时活动重新启动问题 - activity relaunch issue when the Home key is pressed 在Android上按下主键按钮后,活动将失去焦点 - The activity loses focus when home key button is pressed on Android 按HOME按钮不会从配置活动返回小部件ID - Pressing HOME button does not return widget ID from configuration activity 当小部件具有配置活动时,无法从小部件启动活动 - Trouble with launching an activity from a widget, when the widget has a configuration activity 我需要在Android中按下主页键时禁用Home键或执行一些活动 - I need to disable Home Key or perform some activity when home key is pressed in android 从片段返回时,不会调用主页活动的 OnResume() - OnResume() is not called of the home activity when back pressed from a fragment 从孩子的父母活动中检测何时按下孩子的家 - Detecting when home is pressed in a child Activity from Parent Acitvity 按下Home键时出现活动问题 - Activity Problem while home key pressed Android:App Widget配置活动的行为与Activity不同(编辑自:Android:AppWidget未嵌入主屏幕) - Android: App Widget Configuration Activity does not behave like Activity (Edited from: Android: AppWidget not embedding into home screen) 如何在按下主页按钮时终止活动? - How to kill an activity when the Home button is pressed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM