Search code examples
androidandroid-activitylifecycle

Android, Unlimited Number of Activities in a Project and activity lifecycle !


Some days ago I have published my application in Android Marketplace and a question came into my mind during designing and developing application. This question is about limitation or unlimitation of number of activities.

For example, my application includes 37 activities. Is it so much? I want to know for a game such as "Angry Birds" which has more than 200 levels, it has 200 activities?!!

My next question is, assume that I am designing an application which includes 100 activities. User starts application and gos into last activity (such as reading a book). If user wants to close the application what should he do? 100 times press back key on his devise?! If I want to put close button(to help user) in options menu, do I have to repeat it for each activity? because as far as I know each activity has its own menu.

If i put close button in last activity and user clicks on it, program will close. What will happen to other 99 activities? are they still exist in stack? or When I close an application, all activities related to that package will delete from stack.

I have read activities page published by Android but I couldn't find my answers.

Sorry if above questions are stupid questions :) Thank you


Solution

  • In the case of Anry Bairds, I doubt they have 100s of activities, I think they just have one (or possibly a couple) for levels and another for the welcome screen - different levels are probably loaded depending on some parameter that was passed to the activity.

    As for how to handle 100s of loaded activities, first of all, it is very likely that the system will recycle the old ones at the bottom of the stack before you get to the 100th activity. If not, then yes, your user will have to click back through a 100 activities.

    If you want to change the behaviour of what the back button, you can override onKeyDown().

    Or if you want to change the default behaviour of how activities are launched, then take a look at activities launch mode.