Android: What Is Better - Multiple Activities or Switching Views Manually

Android: What is better - multiple activities or switching views manually?

I would say that multiple Activities almost always makes more sense. I just don't think Android is designed for constantly switching its own views - you miss out on so much. You have to implement Back yourself, you don't get any inter-Activity transitions, you have to implement a lot of internal logic to resume an application in the correct state. If you don't partition your app into Activities, it makes it a lot more difficult later on to change the flow of your application. It also results in one mega-Activity that can be a lot harder to handle than a lot of smaller pieces of code.

I have trouble imagining that speed is really an issue; if it is then there's something wrong with the way you're initializing each Activity. For example, I used try to pass Serializable objects between Activities, and that proved to be incredibly slow; when I switched to a faster method of passing objects, the speed of launching Activities increased immensely.

Also, I think it's telling that the Android guidelines for Activity and Task Design don't mention switching Views at all; it's centered around an Activity-as-View design.

Android - Should I use multiple activities or multiple content views

The general rule would be to use multiple activities. That's the way it's meant to be and you won't be breaking navigation (e.g. going to the previous "screen" by pressing back button).

Fragment switching or Multiple activities?

Afaik, the example of dual pane showed in the official documentation specifies 2 fragments and 2 activities, but this isn't a choice you have to do. Both are required.

  • For phones, activity A shows fragment #1 and activity B shows fragment #2.
  • For tablets, activity A shows both fragment #1 and #2, and activity B isn't used.

Should app's with multiple layouts have multiple activities to handle each?

I'd say you want to go with the former, in the most cases, but obviously it all comes down to what it is that should be changing.

If you end up having two activities with layouts that only slightly differ, and you have to pass a lot of data between them, then it probably should have been one activity.

But in the most cases, where you're dealing with presenting quite separate things, I'd definitely create one activity for each presentation, so that you don't have to manually handle things like the click of the back button.



Related Topics



Leave a reply



Submit