2014. 11. 18. 15:58
리시버를 2개 선언하되,
해당 프로바이더는 다른 클래스를 가르키고 있다.
공통된 부분이 있다면 따로 모듈로 빼는 수밖에 없다.
You need a receiver definition for each type in your manifest file like:
<receiver android:name=".MyWidget" android:label="@string/medium_widget_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/medium_widget_provider" />
</receiver>
<receiver android:name=".MyWidget" android:label="@string/large_widget_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/large_widget_provider" />
</receiver>
This would allow you to have the same AppWidgetProvider
class be used for multiple widgets, with different widget names and different sizes defined in the <appwidget-provider>
XML.
Now if you need more differences in your widgets than what is in the <appwidget-provider>
XML I would create a base widget class that implements all the common behavoir between the different types:
public abstract class MyBaseWidget extends AppWidgetProvider
And then each of your concrete implementations could extend MyBaseWidget. Then in your manifest file you would have a receiver definition for each of your concrete implementations like:
<receiver android:name=".MyMediumWidget" android:label="@string/medium_widget_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/medium_widget_provider" />
</receiver>
<receiver android:name=".MyLargeWidget" android:label="@string/large_widget_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/large_widget_provider" />
</receiver>
'JAVA > Android' 카테고리의 다른 글
Adding View to RemoteViews in Android (0) | 2014.11.18 |
---|---|
Adding the AppWidgetProviderInfo Metadata (0) | 2014.11.18 |
App Widgets 에서 사용할 수 있는 레이아웃 (0) | 2014.11.18 |
[SQLite] concat, append String text (0) | 2014.11.03 |
[Android.] UI Thread Handler Main (0) | 2014.10.23 |