Question

I was trying to update ListView item content (with one TextView) on SmartWatch 2 Control via sendListCountWithContent() method:

public class SmartWatch2Control extends ControlExtension {

    private List<String> accs;

    @Override
    public void onResume() {
        accs = Utils.getAllAccounts();
        showLayout(R.layout.smartwatch2, null);
        sendListCountWithContent(R.id.smartwatch2_list, accs.size(),
            bundlesForList(accs));
        sendListPosition(R.id.smartwatch2_list, 0);
    }

    private Bundle[] bundlesForList(List<String> list) {
        Bundle[] result = new Bundle[list.size()];

        for (int i = 0; i < list.size(); i++) {
            Bundle nameBundle = new Bundle();
            nameBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE,
                R.id.acc_name);
            nameBundle.putString(Control.Intents.EXTRA_TEXT, list.get(i));
            Bundle[] views = new Bundle[] { nameBundle };

            Bundle b = new Bundle();
            b.putInt(Control.Intents.EXTRA_DATA_XML_LAYOUT,
                R.layout.smartwatch2_item);
            b.putInt(Control.Intents.EXTRA_LIST_ITEM_ID, i);
            b.putInt(Control.Intents.EXTRA_LIST_ITEM_POSITION, i);
            b.putParcelableArray(Control.Intents.EXTRA_LAYOUT_DATA, views);

            result[i] = b;
        }

        return result;
    }
}

When I try to start the app on SmartWatch 2 emulator I get the exception:

10-19 14:49:17.823: ERROR/AndroidRuntime(8841): FATAL EXCEPTION: main
        java.lang.ClassCastException: android.os.Parcelable[] cannot be cast to android.os.Bundle[]
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.CostanzaListAdapter.<init>(CostanzaListAdapter.java:40)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity.renderListView(ControlActivity.java:632)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity.access$10(ControlActivity.java:624)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity$8.run(ControlActivity.java:447)
        at android.app.Activity.runOnUiThread(Activity.java:4170)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity.onListCount(ControlActivity.java:441)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity.handleEvent(ControlActivity.java:264)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.CostanzaActivity$ServiceMessageHandler.handleMessage(CostanzaActivity.java:240)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4575)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
        at dalvik.system.NativeStart.main(Native Method)

link to test project

Sony does not provide web javadocs on api methods (only intents) so I present here an excerpt:

package com.sonyericsson.extras.liveware.extension.util.control;

public abstract class ControlExtension {

<..>

    protected void sendListCountWithContent(int layoutReference, int listCount, Bundle[] bundles) {
        Intent intent = new Intent(Control.Intents.CONTROL_LIST_COUNT_INTENT);
        intent.putExtra(Control.Intents.EXTRA_LAYOUT_REFERENCE, layoutReference);
        intent.putExtra(Control.Intents.EXTRA_LIST_COUNT, listCount);
        intent.putExtra(Control.Intents.EXTRA_LIST_CONTENT, bundles);
        sendToHostApp(intent);
    }

<..>

}

When I invoke sendListCountWithContent method app sends CONTROL_LIST_COUNT_INTENT intent to host app (SmartConnect), then host app resends intent to Emulator (or connected SmartWatch2) that which builds an layout based on intent extras. Here thrown an ClassCastException.

I am not sure but it is looks like a bug in emulator.

Was it helpful?

Solution

We are aware of this bug and have implemented a fix that will be available in the next release of the Sony Add-on SDK.

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