java - How to stop a Splash Screen with a click before the end? -
i created activity splashscreen in application.
this works animation code :
public class spalshscreenactivity extends activity { private static final int stopsplash = 0; private static final long splashtime = 3000; private boolean flagback = false; private final transient handler splashhandler = new handler() { @override public void handlemessage(message msg) { if (msg.what == stopsplash && !flagback) { startmainactivity(); } super.handlemessage(msg); } }; public void onattachedtowindow() { super.onattachedtowindow(); window window = getwindow(); window.setformat(pixelformat.rgba_8888); } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); settheme(r.style.hideactionbar); setcontentview(r.layout.splash); startanimations(); final message msg = new message(); msg.what = stopsplash; splashhandler.sendmessagedelayed(msg, splashtime); } private void startanimations() { animation anim = animationutils.loadanimation(this, r.anim.alpha); anim.reset(); linearlayout l=(linearlayout) findviewbyid(r.id.lin_lay); l.clearanimation(); l.startanimation(anim); anim = animationutils.loadanimation(this, r.anim.translate); anim.reset(); imageview iv = (imageview) findviewbyid(r.id.logo); iv.clearanimation(); iv.startanimation(anim); } private void startmainactivity() { final intent intent = new intent(spalshscreenactivity.this, mainfragmentactivity.class); startactivity(intent); finish(); } public boolean onkeydown(int keycode, keyevent evt) { if (keycode == keyevent.keycode_back) { flagback = true; finish(); return true; } return false; }}
now add ability click on screen stop splashscreen.
i tried way, works think not optimal solution (slow) :
@override public boolean ontouchevent(motionevent evt) { if(evt.getaction() == motionevent.action_down) { flagback = true; startmainactivity(); } return true; }
thank in advance!
set onclicklistener activity same code in ontouchevent
Comments
Post a Comment