首页 > 解决方案 > 将一个数组值从服务传递到活动

问题描述

我正在尝试通过传递一个从服务到活动不断变化的浮点数组值来制作实时折线图。

服务

public Intent intentfusedOrientation;

public final void onCreate() {
//...
intentfusedOrientation = new Intent(this, Activity.class);

}

class calculateFusedOrientationTask extends TimerTask {
public void run() {

  //...

  intentfusedOrientation.putExtra("fusedOrientation", fusedOrientation[0]);
  startService(intentfusedOrientation);

}
}

活动

   public void addEntry() {

    LineData data = mChart.getData();

    if (data != null) {

        ILineDataSet set = data.getDataSetByIndex(0);

        if (set == null) {
            set = createSet();
            data.addDataSet(set);
        }

        float fusedOrientation = getIntent().getFloatExtra("fusedOrientation",30);
        data.addEntry(new Entry(set.getEntryCount(), fusedOrientation), 0);
        data.notifyDataChanged();

        mChart.notifyDataSetChanged();

        mChart.setVisibleXRangeMaximum(150);

        mChart.moveViewToX(data.getEntryCount());

    }
}

但在图表中,我只得到默认的 getFloatExtra() 值,这里是 30。您知道问题出在哪里,我该如何解决?提前致谢。

标签: javaandroidarraysandroid-intentmpandroidchart

解决方案


推荐阅读