How to Add AppWidget In Android Application

App Widgets are miniature application views that can be embedded in other applications (such as the Home screen) and receive periodic updates.Home screen widgets are broadcast receivers which provide interactive components. They are primarily used on the Android home screen. They typically display some kind of data and allow the user to perform actions with them.

Declaring an App Widget in the Manifest

Adding the AppWidgetProviderInfo Metadata

Define the AppWidgetProviderInfo object in an XML resource using a single <appwidget-provider> element and save it in the project’s res/xml/ folder.

Create a layout such as the one below, that references a dimension resource for its margins:

The most important AppWidgetProvider callback is onUpdate() because it is called when each App Widget is added to a host (unless you use a configuration Activity). If your App Widget accepts any user interaction events, then you need to register the event handlers in this callback. If your App Widget doesn’t create temporary files or databases, or perform other work that requires clean-up, then onUpdate() may be the only callback method you need to define. For example, if you want an App Widget with a button that launches an Activity when clicked, you could use the following implementation of AppWidgetProvider:

If you want to be refresh/update widget view on AppWidget make update widget method, you can invoke the method on click event.

Hope it will help you to know the basic structure of AppWidget.

 

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close