Android的GraphView项目获得冻结与实时更新 [英] Android GraphView project get freeze with real time updates

查看:137
本文介绍了Android的GraphView项目获得冻结与实时更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将安卓GraphView 项目到我的应用程序,所有的时间,我有一些奇怪的问题吧。

我的应用程序需要的实时数据绘制图表。我有螺纹与所有提供数据通信。在主线程我读这个数据,并简单地使用 mSeries1.appendData(新的数据点(计数器,数据[0]),真实,100); 其中计数器为int是每次更新后增加。

不幸的是,在某些时候它冻结。我试着将它放在同步块或改变code中的行 mSeries1.appendData(新的数据点(计数器,计数器),如此,100); ,仍然同样的结果。

这是怎样的内存看起来像应用程序运行过程中,当它冻结:

有没有人有任何想法,在这里可能是什么问题?

编辑:

这是我目前的方法来更新我的图形视图:

 公共无效onEventMainThread(ReadingsUpdateData数据){
        mSeries1.appendData(新的数据点(计数器,data.getData()[0]),真实,100);
        反++;
    }
 

解决方案

虽然你没有指定您加分,以及多长时间的应用程序运行不崩溃,你应该想到事情会出错在某些时候的速度(你可能会产生点对象无限多的,而内存确实有限)。

您是否需要将所有应用程序从一开始就收到画的点?如果没有,你可以实现一种循环缓冲区,只有通过保持你的供应商线产生在X最后的值,并在每次收到一个新值的方法更新时间曲线图

  your_series.resetData(数据点[] my_circular_buffer_of_data_points);
 

<一个href="http://stackoverflow.com/questions/29607087/android-graph-view-laggy-on-huge-data/29627949#29627949">This螺纹颇为相似,你的问题,看看吧!

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++;
    }

解决方案

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 !

这篇关于Android的GraphView项目获得冻结与实时更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆