[Android General] dumb_nobody:
Here is the code for a basic animation program in Android:

[SIZE="2"][FONT="Courier New"]import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.*;
import android.graphics.*;
import javax.xml.parsers.*;
import javax.security.cert.*;

public class MainActivity extends Activity
{
DrawView drawView = null;

@Override public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setTitle("Animation Example");
drawView = new DrawView(this);
setContentView(drawView);
}

@Override public void onPause()
{
super.onPause();
drawView.pause();
}

@Override public void onResume()
{
super.onResume();
drawView.resume();
}
}

class DrawView extends SurfaceView implements SurfaceHolder.Callback
{
DrawThread thread = null;

int screenWidth = 0;
int screenHeight = 0;

int radius = 40;

int boundaryTop = 0;
int boundaryBottom = 0;
int boundaryLeft = 0;
int boundaryRight = 0;

float ppsX = 0; // horizontal velocity in pixels per second
float ppsY = 0; // vertical "

float x = 0;
float y = 0;

long lastDrawTime = 0;

int minIntervalMs = 15; // limit frame rate

Paint paint = null;

public DrawView(Context context)
{
super(context);

paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLUE);

getHolder().addCallback(this);

setFocusable(true);
}

public void initialize(int screen_width, int screen_height)
{
screenWidth = screen_width;
screenHeight = screen_height;

x = screenWidth / 2.0f;
y = screenHeight / 2.0f;

boundaryTop = radius;
boundaryBottom = screenHeight - radius - 1;
boundaryLeft = radius;
boundaryRight = screenWidth - radius - 1;

ppsX = 250;
ppsY = 100;
}

public void startThread()
{
thread = new DrawThread(getHolder());
thread.setRunning(true);
thread.start();
}

public void stopThread()
{
boolean retry = true;
thread.setRunning(false);

while (retry)
{
try { thread.join(); retry = false; }
catch (InterruptedException e) { }
}
}

public void pause()
{
stopThread();
lastDrawTime = 0;
}

public void resume()
{

}

@Override public void surfaceCreated(SurfaceHolder holder)
{
startThread();
}

@Override public void surfaceDestroyed(SurfaceHolder holder)
{
stopThread();
}

@Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{

}

@Override public void onSizeChanged(int width_new, int height_new, int width_old, int height_old)
{
super.onSizeChanged(width_new, height_new, width_old, height_old);

initialize(width_new, height_new);
}

@Override public synchronized boolean onTouchEvent(MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
{
break;
}

case MotionEvent.ACTION_UP:
{
break;
}

case MotionEvent.ACTION_MOVE:
{
break;
}
}

return true;
}

public void updateCanvas(Canvas canvas)
{
if (lastDrawTime != 0)
{
long intervalMs = System.currentTimeMillis() - lastDrawTime; // interval in milliseconds

if (intervalMs < minIntervalMs)
{
try { Thread.sleep(minIntervalMs - intervalMs); }
catch (InterruptedException e) { }
intervalMs = minIntervalMs;
}

float intervalS = intervalMs / 1000.0f; // interval in seconds

x = x + intervalS * ppsX;

if (x < boundaryLeft)
{
x = boundaryLeft;
ppsX = -ppsX;
}
else if (x > boundaryRight)
{
x = boundaryRight;
ppsX = -ppsX;
}

y = y + intervalS * ppsY;

if (y < boundaryTop)
{
y = boundaryTop;
ppsY = -ppsY;
}
else if (y > boundaryBottom)
{
y = boundaryBottom;
ppsY = - ppsY;
}
}

canvas.drawColor(Color.WHITE);
canvas.drawCircle(x, y, radius, paint);

lastDrawTime = System.currentTimeMillis();
}

class DrawThread extends Thread
{
private SurfaceHolder holder = null;
private boolean run = false;

public DrawThread(SurfaceHolder holder)
{
this.holder = holder;
}

public void setRunning(boolean run)
{
this.run = run;
}

@Override public void run()
{
Canvas canvas = null;

while (run)
{
canvas = null;

try
{
canvas = holder.lockCanvas(null);

synchronized (holder)
{
updateCanvas(canvas);
}
}
finally
{
if (canvas != null)
{
holder.unlockCanvasAndPost(canvas);
}
}
}
}
}
}
[/FONT][/SIZE]