1

I'm trying to make real-time line chart by passing one float array value, which is constanly changing, from service to activity.

Service

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);

}
}

Activity

   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());

    }
}

But in a chart I'm only getting default getFloatExtra() value which is 30 here. Do you see what's the problem and how do I fix it? Thanks in advance.

Mantas
  • 11
  • 3
  • I hope this link be helpful.[link](https://stackoverflow.com/questions/18125241/how-to-get-data-from-service-to-activity) – Mohsen Naderzadeh Nov 06 '20 at 18:24
  • it's because your `service` and `activity` is running in separate `thread`. you can use a `handler` to post message from `service` to `activity` – ruben Nov 06 '20 at 19:07

0 Answers0