java – update UI 16 times in a second android-ThrowExceptions

Exception or error:

i am getting data packets at the rate of 16 packets per second so after receiving each packet i need to update my UI but after getting around 40-50 packets , UI stucks completely
Already tries putting in async task but not helping.
in MAinActivity.java i am receiving packets with broadcast receiver and then received location method is called to update the UI

private BroadcastReceiver packetCallback = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {

                String packetType = (String) intent.getSerializableExtra(
                     PocketLinkFacade.EXTRA_PACKET_TYPE);

                DataPacketModel dataPacket;

                switch (packetType) {
                    case PocketLinkFacade.GOT_NEW_PACKET:
                        dataPacket = (DataPacketModel) intent.getSerializableExtra(
                                PocketLinkFacade.EXTRA_DATAPACKET);

                        receivedLocationPacket(dataPacket);  // method to update UI
                        break;

                }
            }
        }; 

Please help with right approach to update UI and same fast rate so that it doesnt freeze the app

How to solve:

you can use these methods to avoid freezing
context.runOnUIThread(Runable);
MyView.post(Runable);
or just ignore the data and just update your view every second;
use a thread with infinite loop and sleep of 1000 ms and put a bool flag in it and on receiving data just check the flag that 1 second is passed to update the UI and turn the flag back.
anyway user cannot read all the data less than a second so basically this much updating-data is not usable to user.

Leave a Reply

Your email address will not be published. Required fields are marked *