简体   繁体   中英

Having a Card in Google Glass Timeline without using Service class (or having a LiveCard without the mandatory PendingIntent Menu Activity)

I am developing an app for Google Glass which basically calls several activities in a workflow sequence (in short: register a video, add some metadata through speech recognition, upload the file to server, close the application); these operations have to be executed in sequence, so I do not need an "options menu".

I managed to do it quite well using Activities only and the startActivityForResult method: I have a main Activity that calls an Activity in turn and waits for its result before calling the subsequent one.

Everything is working fine, But my problem is that this app is "not persistent": II happen to close the application in the middle of the process, by swiping down or by letting the Glass go to standby, I lose the application and therefore all the data collected until then.

This is probably because I have not added any card to the timeline. I would like to add a Static Card, but I cannot use the TimelineItem class (I'm using XE17). I would like to add a LiveCard, but I do not want to add a menu (A PendingIntent for a LiveCard is mandatory), and I want the "workflow" to start immediately, without the need for the user of a second tap.

The only solution I could come by up to now is to add a dummy Activity as a PendingIntent for the LiveCard (in order to make the app happy), and then launch a second Activity inside the onCreate() or onStartCommand() methods of the Service, and this Activity would do the real work (and perhaps return the information to the LiveCard through some binding, in order to avoid loss of data if the application is closed before its natural ending); I would need to launch this second Activity also because there is no equivalent in Service class of the startActivityForResult method.

Still, I'm not sure this solution is possible and I don't think this is the correct way of designing for Glass.

How could I achieve this (TL;DR: having a persistent application with or without a LiveCard but without a menu and with a workflow/pipeline of operations)?

EDIT: this is not really what I wanted, but I found a solution using the classic method for the LiveCard's PendingIntent. Therefore I'm marking the Jessie's answer as correct. For explanations, see my last comment in the answer.

You should be able to set the PendingIntent to be something that isn't a menu. You can specify any random Activity, in this case, your own activity.

You should be able to do something like:

    Intent pendingIntent = new Intent(this, AccountsCard.class);
    pendingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    mLiveCard.setAction(PendingIntent.getActivity(this, 0, pendingIntent, 0));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM