1

I have an android app where I have the same basic activity for both signed and unsigned user. The difference between activities is that I want to implement the sign out button in the overflow menu for the Signed user and some button for saved data.

Should I use the same activity for such thing or separate activities?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Drejc
  • 491
  • 6
  • 21

2 Answers2

3

I personally would recommend having one base activity and two fragments, one for "logged/signed in" users and other for unsigned users.

This particular approach can help you with various problems because you can have the base activity acting as a "controller" to the child fragments. Fragments are more flexible and less expensive in terms of resources. This way you can have one fragment handling the "signed in" state, and calling various methods that can be shareable across the other fragments, cause they are sitting under the same base activities (these methods that are "shareable" should be implemented in the base activity, or in a separated manager, in case you want to use them in other contexts (activities)). For more context about this Fragment vs Activity, have a look at this.

Back to your case, from my experience, I would use this approach instead of showing or hiding stuff, depending on the user state. This is because I always start a simple app, with one generic screen that treats various states, but then the app becomes more complex, and I end up needing to separate one fragment that is showing/hiding stuff depending on the user, to two or more separated fragments. Always treat each state as their own, instead of having one generic one that treats different states.

miguelarc
  • 791
  • 7
  • 13
1

I don't particularly see any reason to duplicate work in order to either add or remove a button from the user interface. This'll complicate your development, testing and maintenance of your code.

I'd recommend using the same activity based off the information you've given.

Will Jones
  • 1,861
  • 13
  • 24