Search code examples
google-gdk

Google glass Live cards implementation


I developed an app with immersion mode for google glass with two activities:

1. Activity_1: Capture image with SurfaceView.
2. Activity_2: View captured image. It works perfect. 

Now I need to make app into Live cards. I have seen the demo from github. Still have confused with Live cards usage. Whether we need to create two services for these activities or else have to create one service for start up activity with livecards. Let me suggest how to implement livecards with these two activities.


Solution

  • The reason live cards need a service is because they can run in the background and a service is just a task that can run in the background (whereas an activity is foreground only).

    You can use a single service to manage as many live cards as you like:

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        mLiveCard1 = new LiveCard(this, LIVE_CARD_TAG_2);
        mLiveCard1.setViews(mView1);
        mLiveCard1.publish(LiveCard.PublishMode.SILENT);
        mLiveCard2 = new LiveCard(this, LIVE_CARD_TAG_2);
        mLiveCard2.setViews(mView2);
        mLiveCard2.publish(LiveCard.PublishMode.SILENT);
    }
    

    However it sounds like you may just be wanting a single live card at a time, so you may want to set it up so that one live card has an action which unpublishes itself and then publishes a new card.