I’m making an Android soundboard. I currently have 12 pages for this specific category. Each page has its own activity and each page as 10 buttons.
Someone asked me today why I don’t just use one activity and switch the setcontentview (XML) between the pages rather then having so many activities.
I thought about it and it doesn’t seem like a bad idea. But I’m curious on if it really would be better.
This means that this one activity would have a 100+ switch case statement for its onclick and onlongclick methods. It would have over 200 variables. I would have to add over 200 listeners (although I think i could set the 10 listeners as I load the specific page rather than all at the beginning. I could also release the current ones before the new XML is displayed).
Will Android be able to handle a single activity like this? I plan on adding more sounds so maybe one day I might have 20 pages or so.
Yes, make it all one activity. Different
Activitiesshould only really be used for completely different use cases. Consider using aListViewor aGridView, or a ‘ViewPager` inside of one Activity.If you do end up using a
ListViewor anything that takes an Adapter, your Activity should look like this: