2
votes

I hate to sound like terrible newb, but are Widgets separate apps? For instance, I am creating a news reader app for Android and I want a homescreen widget. Do I create the widget as a separate project/app that hooks into the other app, or do I add the code for the widget to the original news reader app so that they are installed in tandem?

If it is a separate project/app, then how do I make sure it is installed when the "parent app" is installed, or is that sort of thing totally off base?

Thanks for any help you can offer!

P.S. Also, I have mostly been an iOS user and I'm just now getting into Android and I don't have a phone, just a tablet. So I haven't absorbed common forms and examples yet.

1
Hey can you help me with the news reader app.? Give an idea or snippet.? - user3278077

1 Answers

6
votes

Just wanted to answer my own question in case anyone else comes along looking for answers. The home screen widget for an app is indeed not a separate app. All it takes to initialize a widget is to declare a BroadcastReceiver in the AndroidManifest.xml file.

Mine looks like this:

<receiver android:name=".receivers.PWReceiver" android:label="@string/widget_name">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
    </intent-filter>
    <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_config" />
</receiver>