0

everyone, i would like to have information displayed promptly in my android car app.

I use a GridTemplate in which I want to update the texts of the items. For testing, I have a simple counter, with a timer (10ms) a function is called recursively, which writes the new value into a variable, which in turn is used by the grid when building. It all works, but I can't get the screen to update faster than a second. To redraw the screen, I use invalidate() to re-call onGetTemplate. Is there another possibility to display live data or to speed up the reloading of the screen?

Here some simplyfied code:

public  class MyScreen extends Screen  {
    private int run = 0;

    public MyScreen(CarContext carContext) {
        super(carContext);
    }
    @NonNull
    @Override
    public Template onGetTemplate() {
        looping();
        Row row = new Row.Builder().setTitle("Count:").addText(run+"").build();
        return new PaneTemplate.Builder(new Pane.Builder().addRow(row).build()).setTitle("Wasup").build();
    }

    private void looping() {
        Timer timer = new Timer();
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                looping();
            }
        }, 100);


        run++;

        Log.d("Test",run+"");
        invalidate();
        if(run >=1000){run = 0;}
    }
}
HDonkey
  • 1
  • 1

1 Answers1

0

There's no way for you as a developer to increase the refresh rate of the templates. Additionally, to limit driver distraction, frequent updates are not recommended in general (see page 8 of https://developer.android.com/training/cars/Android%20for%20Cars%20App%20Library%20design%20guidelines.pdf)

Ben Sagmoe
  • 440
  • 2
  • 9