【问题标题】:What is the 'context' that is being passed into the onUpdate, onEnabled, onDeleted, and onDisabled methods of the AppWidgetProvider?传递给 AppWidgetProvider 的 onUpdate、onEnabled、onDeleted 和 onDisabled 方法的“上下文”是什么?
【发布时间】:2011-09-26 18:46:04
【问题描述】:

是我的应用程序的 ApplicationContext 还是 ActivityContext?它是哪一个有区别吗?

【问题讨论】:

    标签: android android-widget android-context


    【解决方案1】:

    是我的应用的 ApplicationContext 还是 ActivityContext?

    你不应该在意。这是一个Context,句号。您所做的任何假设都没有记录在案,并且可能会发生变化。

    话虽如此,由于您的整个应用程序中不一定有Activity,所以Context 不太可能是Activity

    【讨论】:

      【解决方案2】:

      应该是ActivityContext。除了你的方法应该采用..的格式。

      void    onDeleted(Context context, int[] appWidgetIds)
      
      void    onDisabled(Context context)
      
      void    onEnabled(Context context)
      
      void    onReceive(Context context, Intent intent)
      
      void    onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
      

      上下文应该在哪里

      Context myContext
      

      或任何类似性质的东西。

      【讨论】:

      • 甚至可能成为Activity。无论Context 是什么,这似乎都不太可能。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      • 1970-01-01
      相关资源
      最近更新 更多