back stack - Android onBackPressed avoid exit -
when user press button on device want move previous activity
not go home.
for example, if user has opened activities
, stack supposed be:
when user presses back button
, it's supposed get:
and the, if presses button 1 time again:
activity_a [ displayed ]then want disable button avoid go home screen
.
is possible ?
so far, i'm using method, i've read won't supported on android l
:
protected int getactivitiesstacksize() { activitymanager = (activitymanager) getsystemservice(activity_service); list<activitymanager.runningtaskinfo> tasklist = am.getrunningtasks(1); homecoming tasklist.get(0).numactivities; } @override public void onbackpressed() { // pop activity if (getactivitiesstacksize() != 1) super.onbackpressed(); }
activity_a may activity
in project.
you can override button event , move between activities except on activity button should still exit. example
@override public boolean onkeydown(int keycode, keyevent event) { // check if key event button if ((keycode == keyevent.keycode_back)) { //move previous activity homecoming true; } // if wasn't key, bubble default // scheme behavior homecoming super.onkeydown(keycode, event); }
android back-stack onbackpressed
No comments:
Post a Comment