Java tutorial
//package com.java2s; import android.graphics.drawable.AnimationDrawable; import android.os.Handler; import android.os.Message; public class Main { private final static int START = 0; private static Handler aniHandler = new Handler() { public void handleMessage(Message msg) { if (!(msg.obj instanceof AnimationDrawable)) { return; } AnimationDrawable ani = (AnimationDrawable) msg.obj; if (msg.what == START) { ani.start(); } else { ani.stop(); } }; }; public static void startAnimation(final AnimationDrawable ani) { postAnimationMessage(ani, START); } private static void postAnimationMessage(final AnimationDrawable ani, final int what) { aniHandler.postDelayed(new Runnable() { public void run() { Message msg = Message.obtain(); msg.what = what; msg.obj = ani; aniHandler.sendMessage(msg); } }, 5); } }