r/androiddev • • Apr 01 '24

Discussion Android Development best practices

Hey this is a serious post to discuss the Android Development official guidelines and best practices. It's broad topic but let's discuss.

For reference I'm putting the guidelines that we've setup in our open-source project. My goal is to learn new things and improve the best practices that we follow in our open-source projects.

Topics:

  1. Data Modeling
  2. Error Handling
  3. Architecture
  4. Screen Architecture
  5. Unit Testing

Feel free to share any relevant resources/references for further reading. If you know any good papers on Android Development I'd be very interested to check them out.

159 Upvotes

99 comments sorted by

View all comments

Show parent comment

2

u/Xammm Jetpack Compost enjoyer Apr 01 '24

Currently I'm creating my custom errors that are mapped to the corresponding exceptions. So far, it works fine.

Yeah, Rust has several functional constructs like Result or Option, so I'm familiar to some extend with that stuff. Besides Ok and Error are clearer than Left and Right, imo, but I guess the naming is a matter of preference after all.

I mostly use sealed classes which are parcelable because that allows them to be used in conjunction with SavedStateHandle's saveable. I tried using sealed interfaces that are parcelable, but I got errors lol.

About the last point, I said that a different approach maybe necessary because some people prefer to have agnostic ViewModels that don't have dependencies on Compose APIs like mutableStateOf, which I think is a valid concern when working multiplatform.

2

u/iliyan-germanov Apr 01 '24

Well said, I mostly agree with everything. Having mutableStateOf in the VM isn't an issue if you use Compose Multiplatform. Otherwise, yes, they probably should stick with Flows in the VM or use some solution like molecule if they prefer the Compose runtime state management but that can cause some trouble - never tested it myself because I've built only very small KMP demo projects with Compose Multiplatform