Question

I've noticed while trying to switch from one Activity to another within a glass app I've built, the menu seems to get messed up and I get left with a ghost activity displayed in my LiveCard that cannot be closed.

I've reviewed a few of the examples (e.g. Compass) but we don't have any advanced examples for navigation it looks like. Can you help out with defining for me the agreed upon convention thus far for building navigation in apps? This will help fix my issue because I realize I'm creating multiple LiveCards which doesn't seem right.

Activities: Should I create multiple activities or should I recycle the same Activity swapping out the UI instead? If multiple activities, is it a good idea to destroy the previous Activity's service upon loading up a new Activity?

Services: In a broad sense, should there be a single service used by all activities to handle the navigation (switching between Activities)? If just one service, should it ever be stopped/restarted? How do you switch between Activities using the service because we don't have a reference to the service from the Activity or the Binder? Or should there be a service for each Activity to handle the navigation?

LiveCards: I believe only one livecard should be created, so then how do you switch between Activities without creating a new one? Is it the convention to keep a global reference for any service to be able to use this LiveCard?

I've asked a lot of questions and I could be way off base for some of them, but I can use any guidance! I can't really find a good guide on google for defining the expected behavior for nagivation. I come from 3 years as an Android dev, so feel free to be complex in your answers! Thanks guys.

EDIT: In case this helps, here's the code I'm using to go from one Activity to the next:

        mLiveCard = new LiveCard(this, GlobalConstants.LIVE_CARD_TAG_ACTIVITY2);
        mRenderer = new MainRenderer(this);

        mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder()
                .addCallback(mRenderer);

        // Display the options menu when the live card is tapped.
        Intent menuIntent = new Intent(this, Activity2.class);
        menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent,
                0));
        mLiveCard.attach(this);
        mLiveCard.publish(PublishMode.REVEAL);
Was it helpful?

Solution

We're probably all pretty new to GDK so I'm certainly not more of an expert then you. I'll share with you what my experience is so far:

Activities: I only use these when i want to create Immersions. I think the only reason to decide if you want to have multiple or one activity should be readability. If an immersion is all you need then you can start your activity directly instead of using a service.

Services: I found it useful to have one central service. Especially in projects where I have state full objects with a lifecycle that spans multiple activities. In case your navigation depends on the state of e.g. a connection it also makes sense to let the service manage the navigation e.g. start new activities. Activities can interact and provide results to the service with whatever method is appropriate e.g. Intent, Broadcast, Binder, Singleton... I usually go through the list and take the first one that fits the requirement. If i can do what I want to do with intent's then that's usually my first choice.

LiveCards: A central service would also be a good place to manage a livecard that you want to share across other activities. Again the method to expose the live card interface to activities depends on what kind of interface you want (abstract vs direct).

Let me know what you think.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top