> actually add multiple instance of the same widget to the home screen,
> is there a way to prevent this?

You probably don't want to enforce a limit like this, because your
widget might be installed on several home screen apps.  Also, you can
delete widgets by long pressing on them and dragging to the delete
tab.


> Also I am looking into buliding my own app widget container, not a
> home screen replacement, just a container that can host other widgets,
> I read the appwidgethost api doc, is there any sample code or guide on
> how to use the appwidgethost api, thanks a lot!

The Launcher source code is available, but it can be a little
confusing.  From a high level:

1. Start listening for widget updates using AppWidgetHost.startListening()
2. Allocate an appWidgetId using AppWidgetHost.allocateAppWidgetId()
3. Launch AppWidgetManager.ACTION_APPWIDGET_PICK using
startIntentForResult(), sending along the allocated ID and any
additional details in the extras.  This will show a dialog to the
user, allowing them to pick which widget they want bound to the
appWidgetId you just allocated.
4. When the user is finished, use resultCode to determine if the
binding was successful.
5. Use AppWidgetManager.getAppWidgetInfo() to find details for the
newly-bound widget, including its layout dimensions and any
configuration activity.
6. Launch the configuration activity for the widget, if they provided one.
7. Use the AppWidgetHost.createView() helper to create an
AppWidgetHostView that contains the inflated widget, and insert into
your on-screen layout.
8. When user deletes the widget, call
AppWidgetHost.deleteAppWidgetId() so the system can clean up
resources.


A few of those steps may be slightly out of order, it's been awhile
since I've dug into this code.  Hopefully this helps.


-- 
Jeff Sharkey
[email protected]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to