如何强制在配置活动的最新情况?情况、最新

由网友(Rubbish.(废物))分享简介:我正在写与调用被点击了确定按钮时,下面的方法配置活动小组件:I'm writing a widget with a configuration activity which calls the following method when its OK button is clicked:private void o...

我正在写与调用被点击了确定按钮时,下面的方法配置活动小组件:

I'm writing a widget with a configuration activity which calls the following method when its OK button is clicked:

private void ok()
{
    // ...Do Widget Configuration...

    // Force an update
    Context context = getApplicationContext();
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
    AppWidgetManager.getInstance(context).updateAppWidget(widget_id, views);

    // Return the expected result
    Intent result = new Intent();
    result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widget_id);
    setResult(RESULT_OK, result);

    finish();
}

这是几乎是逐字从的文档。 widget_id 认为,在被挖出的小部件ID活动的的onCreate()

This is almost verbatim from the documentation. widget_id holds the widget ID that was dug up during the activity's onCreate().

当我把主屏幕上的小部件的实例,我已经验证了我得到事件的预期顺序:

When I place an instance of the widget on the home screen, I've verified that I get the expected sequence of events:

的onReceive()得到一个 ACTION_APPWIDGET_ENABLED 如果这是第一个。 的OnUpdate()被调用(我在其中发现了小部件未配置和借鉴的东西作为默认操作)。 在配置活动出现。 当我preSS 确定确定()上述方法被调用。 onReceive() gets an ACTION_APPWIDGET_ENABLED if it's the first one. onUpdate() gets called (in which I detect that the widget isn't configured and draw something as a default action). The configuration activity appears. When I press OK, the ok() method above gets called.

该方法获取一路走过来的完成()和配置活动消失,但有以的onupdate没有呼叫()的onReceive()这点之后。 (小部件本身没有 updatePeriodMillis )。我最终有我的默认操作结果屏幕上的一个小部件,但从来没有得到更新。

The method gets all the way through to the finish() and the configuration activity goes away, but there's no call to onUpdate() or onReceive() after this point. (The widget itself has no updatePeriodMillis.) I end up with a widget on the screen that has the results of my default action but never gets updated.

如果我设置了窗口小部件时没有使用配置的活动,它就会被创建的时候,一切都按预期工作(只是没有配置位)进行更新。

If I set the widget up without a configuration activity, it gets updated when created and everything works as expected (just without the configured bits).

我缺少的东西在我强制更新的方式?

Am I missing something in the way I force an update?

谢谢!

推荐答案

这横空出世的工作:

new MyWidgetProviderClass()
  .onUpdate(this,
            AppWidgetManager.getInstance(this),
            new int[] { widget_id }
   );
阅读全文

相关推荐

最新文章