[英]How to know Google Glass TimelineManager LiveCard is resumed
我正在使用Service在Google Glass中開發一個簡單的hello world應用程序。 在我的應用程序中,我使用TimelineManager來顯示LiveCard 。 我想在用戶可見該應用程序時調用一個http調用(我的意思是當用戶從其他應用程序滾動到我們的應用程序時)。
我知道我們是否使用Activity,會自動調用onResume(),但是我正在Service中進行。
請讓我知道將應用恢復給用戶時將調用哪種方法 。
public class MyGlassService extends Service {
private static final String TAG = "SocketService";
private static final String LIVE_CARD_ID = "livecard";
private TimelineManager mTimelineManager;
private LiveCard mLiveCard;
private TextToSpeech mSpeech;
private final IBinder mBinder = new MainBinder();
private TextView txtName, txtBalance;
private RemoteViews remoteView;
private WakeLock screenLock;
public class MainBinder extends Binder {
public void sayMessage() {
mSpeech.speak(getString(R.string.hello_world),
TextToSpeech.QUEUE_FLUSH, null);
}
}
@Override
public void onCreate() {
super.onCreate();
mTimelineManager = TimelineManager.from(this);
mSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
// do nothing
}
});
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
remoteView = new RemoteViews(this.getPackageName(), R.layout.activity_main);
if (mLiveCard == null) {
mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_ID);
remoteView.setTextViewText(R.id.name, getString(R.string.pre_screen_msg));
mLiveCard.setViews(remoteView);
}
return START_STICKY;
}
@Override
public void onDestroy() {
if (mLiveCard != null && mLiveCard.isPublished()) {
mLiveCard.unpublish();
mLiveCard = null;
}
mSpeech.shutdown();
mSpeech = null;
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
public String toHexString(byte[] data) {
String s = new String(data);
return s;
}
}
實時卡不能像活動那樣提供精確的生命周期方法,而活動可以讓您知道用戶何時滾動到一個或滾動一個。
如果您想查看此功能,請在我們的問題跟蹤器上發布功能請求,以描述您的用例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.