Android GraphView project get freeze with real time updates

一个人想着一个人 提交于 2019-12-20 03:26:12

问题


I am trying to incorporate Android GraphView project into my app and all the time I have some strange problem with it.

My app requires drawing graph from real time data. I have thread with all the communication that is providing the data. In main thread I am reading this data and simply use mSeries1.appendData(new DataPoint(counter,data[0]),true,100); where counter is int that is incremented after each update.

Unfortunately at some point it freeze. I've tried putting it in synchronized block or changing the line of code to mSeries1.appendData(new DataPoint(counter,counter),true,100); and still this same result.

This is how the memory looks like during app running and when it freezes:

Does anyone have any idea what might be wrong in here?

EDIT:

This is my current method for updating my graph view:

public void onEventMainThread(ReadingsUpdateData data) {
        mSeries1.appendData(new DataPoint(counter,data.getData()[0]),true,100);
        counter++;
    }

回答1:


Maybe it's too late, but I had the similar problem and finally I found that when GraphView is appended a new data of "NaN" freezes.

So check the situation in which the result will be NaN such as divide by zero or something like that.




回答2:


Although you do not specify the rate at which you add points, and how long for the app runs without crashing, you should expect things to go wrong at some point (you're potentially generating an infinite number of point objects, while the memory is indeed limited).

Do you need to have all the points the app has received from the beginning drawn ? If not, you could implement a sort of circular buffer that only keeps the X last values generated by your "provider thread", and update the graph each time you receive a new value with the method

your_series.resetData( dataPoint[] my_circular_buffer_of_data_points );

This thread is quite similar to your problem, have a look at it !



来源:https://stackoverflow.com/questions/30290575/android-graphview-project-get-freeze-with-real-time-updates

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