How to program a bounded activity history stack

view story

http://stackoverflow.com – How can I keep only last X number of activities when starting new activity instances: For example, keeping last 3 activities: Given: Activity1 -> Activity2 (first instance) -> Activity2 (second instance) Launching Activity 3 will result with a history task having: Activity2 (first instance) -> Activity2 -> (second instance) -> Activity3 (..Activity1 destroyed and removed) I know this is possible because this is how the facebook app behaves, below are adb dumps, which demonstrate the scenario: First dump shows the resident activities after switching a couple of times betw (HowTos)