سؤال

Having Problem updating a LiveCard using remote views. I am publishing using this code. I am assuming that you can get the LiveCard using TimelineManager.getLiveCard(id) and then publishing again. The result I get is two LiveCards. I am using the same id both times I publish the cards.
As a workaround I am unpublishing and then publishing, but that is not a smooth transition as it shows the 'Okay Glass' between.

private void publishCard(Context context) {
    String cardId = "myCard";
    mLiveCard = tm.getLiveCard(cardId);
    mLiveCard.setNonSilent(true);
    RemoteViews rv = new RemoteViews(context.getPackageName(),
            R.layout.activity_vitals_glass);
    rv = updateViews(rv, pr);
    mLiveCard.setViews(rv);
    Intent intent = new Intent(context, MenuActivity.class);
    mLiveCard.setAction(PendingIntent.getActivity(context, 0, intent, 0));
    mLiveCard.publish();
}

The updateViews() method just sets textviews on the remote view. What is the proper way to update a LiveCard with RemoteViews?

هل كانت مفيدة؟

المحلول

getLiveCard creates a new live card, so you should only call it once when your service is started and cache the LiveCard instance that you receive.

You can also cache the RemoteViews instance at the same time. To update the card after it's published, you'll just need to manually call setViews on the LiveCard again after you call any of the RemoteViews setters.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top