问题
I'm trying to figure out if calling super.onUpdate() is recommend when developing an AppWidgetProvider.
public class MyAppWidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
// My code starts here
...
}
}
I'm wondering because it is necessary to call super.onCreate() when developing an Activity. But I can't find anything similar in the JavaDoc: http://developer.android.com/reference/android/appwidget/AppWidgetProvider.html#onUpdate(android.content.Context, android.appwidget.AppWidgetManager, int[])
I also checked the Android sources (2.2 and 4.0):
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/appwidget/AppWidgetProvider.java
Right now the method does nothing, but maybe it will be doing something in future releases. I think that it should be safe to add the call to the method now and also be safe for future releases.
Any recommendations on that?
回答1:
It does not hurt to call onUpdate() here, and, as you say, it may have future value. That being said, I am sure that there are many, many developers not calling onUpdate(), and so if Android shifts such that chaining to the superclass in onUpdate() is critical, I hope Google will shout it from the mountaintops.
来源:https://stackoverflow.com/questions/10860793/super-onupdate-in-appwidgetprovider-recommend