android postDelayed method doesn't work -
i'm trying splash screen app. used postdelayed
method. code:
public class splashscreenactivity extends activity { private static final int splash_duration_ms = 1500; private static final string tag = splashscreenactivity.class.getsimplename(); private handler mhandler = new handler(); public static final int sdkversion = build.version.sdk_int; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.splash_screen); random r = new random(); int imagenumber = r.nextint(2 - 0) + 0; imageview splashscreenbackground = (imageview)findviewbyid(r.id.splash_screen_image); switch (imagenumber){ case 0: if(sdkversion > 20) splashscreenbackground.setbackground(getdrawable(r.drawable.splash_screen_back)); else splashscreenbackground.setbackgrounddrawable(getresources().getdrawable(r.drawable.splash_screen_back)); return; case 1: if(sdkversion > 20) splashscreenbackground.setbackground(getdrawable(r.drawable.buffon)); else splashscreenbackground.setbackgrounddrawable(getresources().getdrawable(r.drawable.buffon)); return; } mhandler.postdelayed(mendsplash, splash_duration_ms); } @override public boolean ontouchevent(motionevent event) { mendsplash.run(); return super.ontouchevent(event); } private runnable mendsplash = new runnable() { public void run() { if (!isfinishing()) { mhandler.removecallbacks(this); log.d(tag, "debugging before intent"); startactivity(new intent( splashscreenactivity.this, mainactivity.class )); log.d(tag, "debugging after intent"); finish(); } }; }; }
and call in oncreate
method:
mhandler.postdelayed(mendsplash, splash_duration_ms);
the problem activity doesn't chnage until press on screen.
another thing, class mainactivity
charged , logs showed don't in screen !!! want know what's problem. thanks
you using return
in switch instead of break
, therefore code handler never reached.
Comments
Post a Comment