postInvalidate() is working slow?

I am using LinearLayout implemented in order to paint polygon on it. But my implemented dispatchDraw(Canvas canvas) method is working very slow.

Approximately, one draw cycle finish in 535ms (milliseconds).

To call myLinearLayout.postInvalidate() from non UI thread, using following code :

myActivity.runOnUiThread(new Runnable() {
    public void run() {

Is there a way to increase drawing speed ?

Please suggest.

Thanks in advance.

Asked by: Fiona799 | Posted: 24-01-2022

Answer 1

The postInvalidate() is designed to use to invalidate the View from a non-UI thread. You don't have to call with the runOnUiThread again.

Answered by: Fenton549 | Posted: 25-02-2022

Similar questions

Android: SurfaceView ignoring postInvalidate()?

It's the first time I'm using this so I'm not sure whether its a bug in my code or I'm trying to do something thats not allowed. Currently, I have a DrawThread() which does this in the run method. try { c = m_surfaceHolder.lockCanvas(null); synchronized (m_surfaceHolder) { m_view.onDraw(c); } } finally { if (c != null) { m_surfaceHolder.unlockCanvasAndPost(c); } }

android - What does postInvalidate() do?

What is the use of the postInvalidate() function in Android? I have been seeing this function in a lot of places. When I Googled, I came out with this much: postInvalidate-- post an invalidate request on the UI-thread I don't know what the phrase "invalidate request" there means. Can someone explain in detail what is happening here?

What is the difference between Android's invalidate() and postInvalidate() methods?

What is the difference between Android's invalidate() and postInvalidate() methods? When does each one get called? Must the methods be called only in classes which extend View?

java - SurfaceView, onDraw and postInvalidate() something wrong

App behave itself strangely. I have a class extends the SurfaceView and implements SurfaceHolder.Callback . I tried 3 options of code and only one works like i need (but I'm doubt that it is a right solution) and other have different behavior. So, my question is why and what is wrong and if "right" solution is wrong, so why it's work... Right for all: I tried setWillNotDraw(boolean flag)

java - postInvalidate() causes heap

I have set up a system to move certain images in an application, but my postInvalidate() calls seem to cause a lot of heap space. private class update extends TimerTask { @Override public void run() { long timestamp = System.currentTimeMillis() - prevTime; prevTime = System.currentTimeMillis(); speed += (speedIncrease / 5 * timestamp); location.y += (int...

paint - Painting with Android - invalidate() or postInvalidate()

I've been getting back into the Android OS and decided to investigate canvas and painting. I came across some code here that creates a simple paint application. But I am alittle confused about one thing. In the paint class it does this: public boolean onTouch(View view, MotionEvent event) { // Point ...

android - UI thread sleeping even though postInvalidate() has been called to trigger onDraw()

I have a problem with postInvalidate with my view. I have a thread called MainFormViewRefresh that wakes up periodically and only calls the postInvalidate() method for my view. This should wake the main UI thread and eventually call the view's onDraw() method and have it redrawn, but the main thread is just sleeping long times even when postInvalidate()...

android - What is difference b/w invalidate() and postInvalidate()?

I am using PostInvalidate(40, Rect); means After 40 miliseconds it should again call the OnDraw() but it seems it is taking more than 40 miliseconds in calling onDraw(). Shall I invalidate() this on timer or handler. It is necessary for me to call it within 40 miliseconds Any suggestions

java - Android: Use postInvalidate() or a direct call to onDraw?

From what I understand, direct calls can be made to the onDraw method, and postInvalidate() simply calls the onDraw method from a separate thread. If I understand correctly (and correct me if I'm wrong), both seem to produce the same result. Is there a difference between postInvalidate() and a direct call to onDraw? Is one a better practice than the other?

android - Why OnDraw is not firing when I call postInvalidate()?

I'm trying to draw GridView on Activitie's layout, but onDraw() method is not being triggered. What can be wrong? Custom view class package com.example.twinkle94.lab_work; import android.content.Context; import; import; import; import android.util.AttributeSet; import android.widget.G...

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android