使用 Google Glass GDK,我正在尝试组合一个简单的应用程序来显示/更新实时卡片。在我的服务中,我有以下方法:
private void publishCard(Context context) {
Card updatedCard = new Card(context);
updatedCard.setText("Foo");
updatedCard.setInfo("Bar");
RemoteViews cardViews = updatedCard.toRemoteViews();
if (cardViews == null)
Log.e(TAG, "Appears to happen every time!")
// Then do some other stuff that fails because of a null RemoteViews
}
正如您在上面看到的,空值检查似乎每次都失败。知道为什么会这样吗?
我的想法是我正在调用它并将服务作为上下文而不是活动传递,也许你不应该这样做?但是,如果是这种情况,您将如何更新 Live Card?我能够从 XML 构建 RemoteViews,但是能够使用 Card 会大大简化事情。