Recently work relatively busy, so had to write some blog on the weekend, hehe. In 3 years of Android work accumulated a lot of experience, I will slowly put my experience in the work to write to everyone! OK, now put a piece of code, is about pressing two times the return key to quit the application of the actual code!
private static Long exittime = 0;
public static void Onbackpressedagain (Activity paramactivity)
{
log.i (TAG, "Onbackpressedagain" + paramactivity.getclass (). Getsimplename ());
if ((System.currenttimemillis ()-Exittime) > 2000)
{
Toast.maketext (paramactivity, "Press again to exit the program", Toast.length_short). Show ();
exittime = System.currenttimemillis ();
}
Else
{
LOG.I (TAG, "Press two Return key");
//exit the entire application
Intent Intent = new Intent (intent.action_main);
intent.addcategory (intent.category_home);
intent.setflags (intent.flag_activity_new_task);
paramactivity.startactivity (intent);
paramactivity.finish ();
}
}
Call attention: Rewrite activity in the onbackpressed function, you must remember to super.onbackpressed () commented out, otherwise there is no effect of Oh!
@Override
public void onbackpressed ()
{
Onbackpressedagain (this);
//super.onbackpressed (); Remember to comment out this line
}
This article from "Dan Dan Home" blog, reproduced please contact the author!
Android Press two times back key to exit the app