Skip to content

Most visited

Recently visited

navigation

AppWidgetHost

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.

Summary

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

Public constructors

AppWidgetHost

Added in API level 3
AppWidgetHost (Context context, 
                int hostId)

Parameters
context Context
hostId int

Public methods

allocateAppWidgetId

Added in API level 3
int allocateAppWidgetId ()

Get a appWidgetId for a host in the calling process.

Returns
int a appWidgetId

createView

Added in API level 3
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

deleteAllHosts

Added in API level 3
void deleteAllHosts ()

Remove all records about all hosts for your package.

  • Call this when initializing your database, as it might be because of a data wipe.
  • Call this to have the AppWidget manager release all resources associated with your host. Any future calls about this host will cause the records to be re-allocated.

deleteAppWidgetId

Added in API level 3
void deleteAppWidgetId (int appWidgetId)

Stop listening to changes for this AppWidget.

Parameters
appWidgetId int

deleteHost

Added in API level 3
void deleteHost ()

Remove all records about this host from the AppWidget manager.

  • Call this when initializing your database, as it might be because of a data wipe.
  • Call this to have the AppWidget manager release all resources associated with your host. Any future calls about this host will cause the records to be re-allocated.

startAppWidgetConfigureActivityForResult

Added in API level 21
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:

startListening

Added in API level 3
void startListening ()

Start receiving onAppWidgetChanged calls for your AppWidgets. Call this when your activity becomes visible, i.e. from onStart() in your Activity.

stopListening

Added in API level 3
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.

Protected methods

clearViews

Added in API level 11
void clearViews ()

Clear the list of Views that have been created by this AppWidgetHost.

onCreateView

Added in API level 3
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

onProviderChanged

Added in API level 3
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

onProvidersChanged

Added in API level 17
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.)

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.