Android Wearable API: how to pass a dynamic List?

风格不统一 提交于 2019-12-12 01:17:00

问题


This is how I'm using DataAPI

    PutDataMapRequest dataMapReq = PutDataMapRequest.create(PATH);
    dataMapReq.getDataMap().putFloatArray(KEY, list);
    PutDataRequest putDataReq = dataMapReq.asPutDataRequest();
    Wearable.DataApi.putDataItem(mGoogleApiClient, putDataReq);

list could be an array[] or ArrayList<>. If I add a new element then I'll have to put the list in the data map again. This will cause a retransmission of every previously inserted elements?


回答1:


Yes, if you change an element in the array/list, you need to put another data item and it will replace the old one. That will cause retransmission to the other devices.

In general, I wouldn't worry about that retransmission. Since there is a limit of how much you can send in the DataItem, you are probably not sending too much data. If you are still worried about it, consider partitioning the data and sending several data items (for example send four sub-arrays of floats and merge them on the other side). Do not send each float a separate data item (enormous overhead).



来源:https://stackoverflow.com/questions/31406728/android-wearable-api-how-to-pass-a-dynamic-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!