public
class
AppWidgetHost
extends Object
java.lang.Object | |
↳ | android.appwidget.AppWidgetHost |
AppWidgetHost provides the interaction with the AppWidget service for apps, like the home screen, that want to embed AppWidgets in their UI.
Public constructors | |
---|---|
AppWidgetHost(Context context, int hostId)
|
Public methods | |
---|---|
int
|
allocateAppWidgetId()
Get a appWidgetId for a host in the calling process. |
final
AppWidgetHostView
|
createView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget)
Create the AppWidgetHostView for the given widget. |
static
void
|
deleteAllHosts()
Remove all records about all hosts for your package. |
void
|
deleteAppWidgetId(int appWidgetId)
Stop listening to changes for this AppWidget. |
void
|
deleteHost()
Remove all records about this host from the AppWidget manager. |
final
void
|
startAppWidgetConfigureActivityForResult(Activity activity, int appWidgetId, int intentFlags, int requestCode, Bundle options)
Starts an app widget provider configure activity for result on behalf of the caller. |
void
|
startListening()
Start receiving onAppWidgetChanged calls for your AppWidgets. |
void
|
stopListening()
Stop receiving onAppWidgetChanged calls for your AppWidgets. |
Protected methods | |
---|---|
void
|
clearViews()
Clear the list of Views that have been created by this AppWidgetHost. |
AppWidgetHostView
|
onCreateView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget)
Called to create the AppWidgetHostView. Override to return a custom subclass if you need it. |
void
|
onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidget)
Called when the AppWidget provider for a AppWidget has been upgraded to a new apk. |
void
|
onProvidersChanged()
Called when the set of available widgets changes (ie. |
Inherited methods | |
---|---|
From
class
java.lang.Object
|
AppWidgetHost (Context context, int hostId)
Parameters | |
---|---|
context |
Context
|
hostId |
int
|
int allocateAppWidgetId ()
Get a appWidgetId for a host in the calling process.
Returns | |
---|---|
int |
a appWidgetId |
AppWidgetHostView createView (Context context, int appWidgetId, AppWidgetProviderInfo appWidget)
Create the AppWidgetHostView for the given widget. The AppWidgetHost retains a pointer to the newly-created View.
Parameters | |
---|---|
context |
Context
|
appWidgetId |
int
|
appWidget |
AppWidgetProviderInfo
|
Returns | |
---|---|
AppWidgetHostView |
void deleteAllHosts ()
Remove all records about all hosts for your package.
void deleteAppWidgetId (int appWidgetId)
Stop listening to changes for this AppWidget.
Parameters | |
---|---|
appWidgetId |
int
|
void deleteHost ()
Remove all records about this host from the AppWidget manager.
void startAppWidgetConfigureActivityForResult (Activity activity, int appWidgetId, int intentFlags, int requestCode, Bundle options)
Starts an app widget provider configure activity for result on behalf of the caller.
Use this method if the provider is in another profile as you are not allowed to start
an activity in another profile. You can optionally provide a request code that is
returned in onActivityResult(int, int, android.content.Intent)
and
an options bundle to be passed to the started activity.
Note that the provided app widget has to be bound for this method to work.
Parameters | |
---|---|
activity |
Activity :
The activity from which to start the configure one. |
appWidgetId |
int :
The bound app widget whose provider's config activity to start. |
intentFlags |
int :
Optional intent flags. |
requestCode |
int :
Optional request code retuned with the result. |
options |
Bundle
|
Throws | |
---|---|
ActivityNotFoundException |
If the activity is not found. |
See also:
void startListening ()
Start receiving onAppWidgetChanged calls for your AppWidgets. Call this when your activity becomes visible, i.e. from onStart() in your Activity.
void stopListening ()
Stop receiving onAppWidgetChanged calls for your AppWidgets. Call this when your activity is no longer visible, i.e. from onStop() in your Activity.
void clearViews ()
Clear the list of Views that have been created by this AppWidgetHost.
AppWidgetHostView onCreateView (Context context, int appWidgetId, AppWidgetProviderInfo appWidget)
Called to create the AppWidgetHostView. Override to return a custom subclass if you need it.
Parameters | |
---|---|
context |
Context
|
appWidgetId |
int
|
appWidget |
AppWidgetProviderInfo
|
Returns | |
---|---|
AppWidgetHostView |
void onProviderChanged (int appWidgetId, AppWidgetProviderInfo appWidget)
Called when the AppWidget provider for a AppWidget has been upgraded to a new apk.
Parameters | |
---|---|
appWidgetId |
int
|
appWidget |
AppWidgetProviderInfo
|
void onProvidersChanged ()
Called when the set of available widgets changes (ie. widget containing packages are added, updated or removed, or widget components are enabled or disabled.)