Friday, 15 March 2013

Android: AnimationDrawable Not working with Runnable -



Android: AnimationDrawable Not working with Runnable -

public class mainactivity extends activity{ public static runnable startrun; private imageview player; protected void oncreate(){ ... player = (imageview) findviewbyid(r.id.imgstart); startrun = new runnable(){ @override public void run() { player.setbackgroundresource(r.drawable.loadanimation); //xml animationlist animationdrawable frameanimation = (animationdrawable) player.getbackground(); frameanimation.start(); } }; } }

public class radioplayer extends service{ handler handle; public void oncreate(){ handle = new handler(); } public int onstartcommand(intent intent, int flags, int startid) { handle.post(mainactivity.startrun); if (intent.getbooleanextra(action_play, false)) { play(); } homecoming service.start_sticky; } }

i have tested animationdrawable section of code straight in oncreate(), work. have used logcat confirm startrun, run() getting called, & have tried define imageview within method not utilize global @ moment.

still, no cigar. can help?

update: seem there underlying issue casuing error. have executed animationdrawable code outside of runnable thread, i.e straight on activity (proof animation work, impracticable myself), have tryed utilize localbroadcastreceiver, handlers etc non of these non-direct-to-activity methods successful , have completly run out of ideas.

with lack of time, have resorted replacing frame animation code simple progressdialog. in way achieves purpose, make-do settlement need addressed 1 time again in few months. if has same issues , can shed lite on subject, please comment/post

i think should start animation on onwindowfocuschanged method because best place know if activity visible user. runnable in code showing animation presume. should work:

public void onwindowfocuschanged(boolean hasfocus) { super.onwindowfocuschanged(hasfocus); if (hasfocus) { player.setbackgroundresource(r.drawable.loadanimation); //xml animationlist animationdrawable frameanimation = (animationdrawable) player.getbackground(); frameanimation.start(); } }

android runnable android-handler

No comments:

Post a Comment