Friday 31 August 2012

Android Widget Development

Android developers can create widget applications that users display and interact with on their device homescreens. Android widget development is a little different to standard Android application development. In this article we will run through some of the ways in which developing widget app differs from developing ordinary apps for the Android platform. If you are hoping to attempt Android widget development, it is recommended that you try creating a standard app first, before moving onto widget apps.

Differences Between Widget Apps and Standard Apps


Many aspects of application structure remain the same between Android widget apps and other apps. One of the main ways in which widgets differ is in how they are launched. Rather than the user launching the app by selecting it in their device menu or from a shortcut icon, with a widget application the user must add it to their device homescreen display. This is normally accomplished by long-pressing the homescreen and selecting the widget from a list. Widget applications are downloaded and installed using the same procedure as for other applications. Once a widget is on the user's screen, it will typically continue to run until the user removes it.

Some widget apps update with information from the Internet or from the system itself. For example, common widgets display information about the phone itself, such as the battery level, network connectivity and phone settings. Additionally, many widget apps retrieve data over the Internet, which is then displayed within the widget user interface. Many widgets are not interactive, simply displaying information within a graphical presentation. However, some can be configured by pressing the widget icon, then choosing settings. Such apps require a more advanced level of development than the ones that are not interactive.

Application Elements


In many ways the elements of a widget app are the same as those in other apps, with a few fundamental differences. With a widget, you don't need to implement a main Activity to launch when the app starts up. Instead, you extend "AppWidgetProvider" and provide methods specifying what should happen when your widget updates. The widget will be automatically updated at a period you specify within your application metadata. This comprises an XML file in your Resources directory. You also need to specify the widget class and metadata in your application Manifest XML. Within the XML metadata for a widget, you can also dictate the dimensions and other properties of your app.

Options

These are the main options in a widget app, but there are many other possibilities. For example, if you need your app to update at a greater frequency than what is allowed when declaring it in the XML resources, which is at most every 30 minutes, you can provide a class extending the "AlarmManager" class. You can optionally also register one or more of your app classes to receive system broadcasts. These are announcements that are available system-wide, often pertaining to information about phone state. Widget layouts are also subject to some restrictions. For example, you can only use certain layout types for an Android widget, including Frame, Linear and Relative layouts. Optionally, you can create an Activity which the Android system will run when your app starts up. This is commonly used to set configuration options for widgets.

Approaching Development


Although widget apps are developed and released using the same process as normal apps, the testing process is sometimes a little more complex. There is a significant limit to the value of testing certain widgets using an Android emulator, or virtual Android device. The most reliable approach is therefore to run these apps on real devices over a period of time in order to gain a true sense of how well they function. This is particularly the case for widgets that receive system broadcasts and other announcements, as these announcements are not entirely authentic on an emulator. For example, the battery level on the emulator by default stays at 50%, which is not very helpful if you are attempting to create a battery level widget.

Devices

As with any Android app, developers need to consider the increasing range of devices running the Android platform when constructing widgets. This is especially so for design matters. Sticking to designs that are relative and will adapt gracefully across different screen sizes is doubly important for widget applications, since they basically comprise visual displays of information. Again, thorough testing is essential to result in a widget app that will function reliably and therefore be a success.

See also:

No comments:

Post a Comment