Android: Determine the last activity in the Activity Stack

Android is a tricky language, the concept of exiting the application is not like any other operating system.In fact concept of application itself is different. When press back from the last activity the user gets a feeling that the application is closed, but the app still remain in the memory ready to quick launch when you start next time.If you want to prompt the user for confirmation when he press the back button on the last activity. You could override finish method, show a dialog.


But what if the same activity is launched multiple times in application? the user gets the prompt every time he press on the child activities as well, to avoid this we need to check for the original intent launched the activity, check the intent categories and if it has Launcher category, we bring up the dialog and do our stuff.