android - Issue with clicking tow buttons at the same time -
i have 3 activities. in activity_second when user click button_right, activity_second destroy , activity_third starts; 1 time again in activity_second when user click button_left, activity_second destroy , activity_first starts.
every thing working fine until user click both buttons @ same time, bang , app crashes. why happening , how can solve problem.
note: need destroy activity_second because gets couple of mediaplayers , result lot of space , need release memory.
here java code activity_second:
public class sec extends activity implements onclicklistener{ @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.second); right = new intent(getapplicationcontext(), third.class); left = new intent(getapplicationcontext(), first.class); imageview button_left = (imageview) findviewbyid(r.id.button_left); imageview button_right = (imageview) findviewbyid(r.id.button_right); button_left.setonclicklistener(this); button_right.setonclicklistener(this); } @override public void onclick(view item) { if(item.getid() == r.id.button_left) { left.addflags(intent.flag_activity_clear_top); startactivity(left); this.ondestroy(); } else if(item.getid() == r.id.button_right) { right.addflags(intent.flag_activity_clear_top); startactivity(right); this.ondestroy(); } } }
try may help you,
public class sec extends activity implements onclicklistener{ @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.second); imageview button_left = (imageview) findviewbyid(r.id.button_left); imageview button_right = (imageview) findviewbyid(r.id.button_right); button_left.setonclicklistener(this); button_right.setonclicklistener(this); } @override public void onclick(view item) { if(item.getid() == r.id.button_left) { intent left = new intent(second.this, first.class); left.addflags(intent.flag_activity_clear_top); startactivity(left); finish(); } else if(item.getid() == r.id.button_right) { intent right = new intent(second.this, third.class); right.addflags(intent.flag_activity_clear_top); startactivity(right); finish(); } } }
android button android-intent android-activity
No comments:
Post a Comment