简体   繁体   English

Android:将小部件放到主屏幕上时启动活动

[英]Android: Launching an activity when a widget is dropped onto the homescreen

If any of you are familiar with Twitter's Android widget, when you place it on your homescreen, an activity launches where you can select the type of tweets you want the widget to display. 如果您熟悉Twitter的Android小部件,则将其放在主屏幕上时,将启动一个活动,您可以在其中选择要显示小部件的推文类型。 I'm hoping to implement something like that in my own widget. 我希望在自己的小部件中实现类似的功能。 I read up on it and found this answer: 我仔细阅读并找到以下答案:

How to apply changes to widget when placing it on the homescreen in onEnabled? 在onEnabled上将其放置在主屏幕上时如何将更改应用于窗口小部件?

This user says the onEnabled method is unreliable due to the way Android manages widget ids. 这位用户说,由于Android管理小部件ID的方式, onEnabled方法不可靠。 I was wondering if anyone knew of an alternative method to launch an activity when a widget is placed on the home screen. 我想知道是否有人知道将小部件放在主屏幕上时启动活动的另一种方法。

Furthermore, I've found that onEnabled is called as soon as you select the widget from the widget menu, NOT when it is placed on the screen. 此外,我发现只要从窗口小部件菜单中选择窗口小部件,就会立即调用onEnabled,而不是将其放置在屏幕上时调用。 This would cause any sort of settings activity to be launched before the user is ready for it. 这将导致在用户准备就绪之前启动任何类型的设置活动。

Thanks guys. 多谢你们。

I was barking up the wrong tree. 我叫错了树。 This is what you want to do here: http://developer.android.com/guide/topics/appwidgets/index.html#Configuring 这是您要在此处执行的操作: http : //developer.android.com/guide/topics/appwidgets/index.html#Configuring

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

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