i am fighting with android hardware backbutton
now my question to you is can i restrict its functionality upto 3 or 4 levels?
right now for example, i have 1,2,3,4,5,6,7,8,9,10 activities
i go to 1 then 2 then 3 …. upto 10 and start pressing backbutton
it takes me to 9 then 8 then 7 upto end
i want to keep track of only last three levels is this possible or not?
any help would be appreciated.
You are welcome to keep count, perhaps using an integer. Use
onBackPressed()(Android 2.x) andonKeyDown()(Android 1.x) to detect BACK button presses. If you chain to the superclass, normal BACK processing will occur. If you do not chain to the superclass, normal BACK processing will not occur.Now, bear in mind that the user can press other keys, like HOME, or the user might respond to a notification (e.g., incoming text message). In those cases, it is possible that your counts may get out of sync with the actual user navigation. Hence, I encourage you to find some other UI pattern that does not involve artificially restricting the BACK button between activities in the fashion that you have outlined here.