There are two main functions of the handler class
(1) Send a message in a newly started thread
(2) Get and process messages in the main thread
public class Mainactivity extends Activity {
Private ImageView IV;
int[] Imageids = new int[] {r.drawable.fy_d_go, R.DRAWABLE.FY_D_KF,
R.drawable.fy_d_kf2, R.drawable.ic_launcher};
int currentid = 0;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
IV = (ImageView) Findviewbyid (R.ID.IMAGEVIEW1);
Final Handler mhandle = new Handler () {
@Override
public void Handlemessage (Message msg) {
if (msg.what = = 0x1233) {
Iv.setimageresource (imageids[currentid++% imageids.length]);
}
}
};
New Timer (). Schedule (new TimerTask () {
@Override
public void Run () {
Mhandle.sendemptymessage (0x1233);
}
}, 0, 1200);
}
}
Android Handler Usage