i need quit application, have referred links in stack overflow , on other sites, have used finishaffinity()
, finish()
, system.exit(0)
still not able achieve it. overriding onbackpressed method in main activity , terminating application.
actually works fine when press button after launching application. when move on other activities , come mainactivity, not working. if use finishaffinity()
opening camera activity 1 of activity in project. if use finish()
opening second page activity.
i post code reference.
mainactivity.java
@override public void onbackpressed() { if (back_pressed + 2000 > system.currenttimemillis()) { log.e("called", "back pressed"); finish(); } else { toast.maketext(getbasecontext(), "press twice exit!", toast.length_short).show(); } back_pressed = system.currenttimemillis(); }
whenever wish exit open activities, should press button loads first activity runs when application starts clear other activities, have last remaining activity finish. apply following code in ur project
intent intent = new intent(getapplicationcontext(), firstactivity.class); intent.setflags(intent.flag_activity_clear_top); intent.putextra("exit", true); startactivity(intent);
the above code finishes activities except firstactivity. need finish firstactivity's enter below code in firstactivity's oncreate
if (getintent().getextras() != null && getintent().getextras().getboolean("exit", false)) { finish(); }
and done....
for more detail ..exit android application programmatically
Comments
Post a Comment