Note that there are some explanatory texts on larger screens.

plurals
  1. POThreading UI updates in Android
    primarykey
    data
    text
    <p>I've just started with android development and updating the UI is really bugging me :/</p> <p>This is what I've got working so far -</p> <pre> package projects.Move; import android.os.Bundle; import android.view.View; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Color; public class Move extends Activity { private float y = 0; private long now = 0; private float delay = 75; private Paint paint = new Paint(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new SimpleMotion(this)); paint.setColor(Color.BLACK); } private class SimpleMotion extends View { public SimpleMotion(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { float x = canvas.getWidth() / 2; canvas.drawColor(Color.WHITE); canvas.drawCircle(x, y, 30, paint); if(System.currentTimeMillis() - now > delay) y++; invalidate(); } } } </pre> <p>It works fine but everybody says that doing your graphics in the main thread, so I'm trying (and failing) to pass it off to another thread. Trouble is, I have absolutely no idea how since really I've never used Threads.</p> <p>The examples that Google gives on using Threads doesn't seem to be very clear and I couldn't really follow it for what I want to do. Could I ask somebody out here to give me the most basic example of how I could do what I'm doing here efficiently using Threads?</p> <p>Thanks in advance :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload