更新Google Glass中的卡片文字

时间:2014-08-05 21:33:51

标签: google-glass gdk

My Glass应用非常简单。我有一张静态卡,我设置了它的文本并显示在被覆盖的" onCreate()"我的活动方法:

myCard.setText("First text");
View cardView = myCard.getView();
// Display the card we just created
setContentView(cardView);

我想睡5秒然后显示" Second Text"给用户。 StackExchange上的一个早期问题讨论了如上所示的新视图,并再次调用setContentView()。

到目前为止这很好,但我天真的问题是,我在哪里睡觉并重置内容视图?显然我不能睡在" onCreate()"或" onStart()"活动,因为还没有为用户呈现显示。我有一个简单的服务。在服务?我在某处创建一个线程并使用它吗?谢谢!

1 个答案:

答案 0 :(得分:1)

无需启动新线程或睡眠。您可以使用Android的Handler.postDelayed方法执行此操作,该方法会在稍后的时间点发布要在UI线程上执行的任务。

public class MyActivity {
    private Handler mHandler = new Handler();

    @Override
    protected boolean onCreate() {
        myCard.setText("First text");
        View cardView = myCard.getView();
        // Display the card we just created
        setContentView(cardView);

        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                updateCard();
            }
        }, 5000 /* 5 sec in millis */);
    }

    private void updateCard() {
        // update the card with "Second text"
    }
}
相关问题