Из основного класса выполняю в методе onCreate 'setContentView(R.layout.activity_main);' In activity_main I connect a class for drawing the playing field + some calculations:
<com.example.sapeg.myapplication.MyDraw android:id="@+id/view" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="7"/> Question: why does the JVM perform twice the calculations that are in the class MyDraw (twice calls the onDraw method). This is the first pass further called once per request. Though I wrote "multithreading", but through LogCat it turned out that all this is done in one stream "main".
onDrawmethodonDrawcalled every time the system considers it necessary to redraw the object, and the extra calculations in this method are already on your conscience. - woesssonDraw? - sapegonDrawyou have to draw your content into the providedCanvasand that’s all you need from it. It is called when an event occurs that affects your view (appearance on the screen, click, shift, sneeze, puff)), as well as at your request:view.invalidate()- woesssonDrawruns twice, the shape moves from the place I need. - sapegonDrawtake the values from these fields. Call the calculation according to the logic of the change of location, and not fromonDraw. Then it will not depend on his calls. For example, the initial position can be calculated in the constructor, and then by clicking the button or how you should have it. - woesss