super.onUpdate() in AppWidgetProvider recommend?

和自甴很熟 提交于 2019-12-10 18:22:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!