I am trying to create an application for Android. My application will need to be a service that runs in the background, a UI application for configuring the service, and a desktop widget for turning the background service off and on.
My question is, how is this typically done in android? Do I need 3 separate applications? Or can I create one application that contains my service, my UI and my widget? I know of applications that do this, such as Weather.com, which has a desktop widget, a service which sits in the notification area and a UI application for configuring the service and widget. Weather.Com is a single download from the market, so I'm assuming this can be done in one application. Can someone please point me in the direction of a tutorial or code examples for doing this?
Of course only one application. Search for appwidget tutorials, there are plenty. You'll get broadcasts for your widget which you handle in one class. Another class for the GUI stuff (well, at least one) and another one for the service. You declare each part in the manifest, so your GUI will have an "Activity" declaration there, your service a "Service" and for the widget a "Receiver":
<activity android:name="MainActivity" />
<service android:name="MainService" />
<receiver
android:name="MyWidget"
android:label="MyWidget Desc" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_info"
/>
</receiver>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.