r/android_devs • • Aug 09 '20

Discussion Those who are getting started on Android Development, what can be done to make your life easier?

What do you wish for to exist, that would make your Android Dev journey much more pleasant?

Apart from the official docs or official materials, what can other devs or content creators create so you will have a good understanding of Android Dev as a whole?

13 Upvotes

28 comments sorted by

15

u/tatocaster Aug 09 '20 edited Aug 09 '20

don't release a new library every week, don't deprecate after a year and don't push alpha releases as production-ready recommended libraries.

But truth be told, Android is way better to work with now than it was 4 years ago and more friendly for newcomers.

3

u/[deleted] Aug 09 '20

We can probably have list of recommended libraries for most scenarios and when to use what and why.

Libraries will probably keep coming by official or by the community. Thanks for your suggestions : )

1

u/deathssoul Aug 09 '20

I'd love to see that as a veteran. Just having a single place for things is a lot easier than looking back at old projects to get to correct libraries.

2

u/[deleted] Aug 09 '20

Noted. Yes, a place like GitHub readme which lists recommended libraries for most scenarios and has link to open-source repo of corresponding up to date implementation in Android App as a reference?

8

u/3dom Aug 09 '20

If a person can figure out Jetpack MVVM, Room, data binding, navigation, Retrofit, recycler + coroutines - they aren't exactly newcomers but middle-level developers.

I remember how going from ListView to Recycler was a considerable effort since it couldn't handle click listeners on its own.

7

u/Zhuinden EpicPandaForce @ SO Aug 09 '20

ListView to Recycler was a considerable effort since it couldn't handle click listeners on its own.

On the other hand, people on Stack Overflow did really magical (and otherwise completely unnecessary) things to get click handling back in a RecyclerView.

Like overriding interceptTouchEvent and stuff. Totally no reason to do that.

Just define a click listener interface, and set it in onCreateViewHolder, pass the item using holder.getAdapterPosition(), but check for >= 0.

People wrote their own "click" handling instead of just using click handling.

2

u/belovedk Aug 11 '20

Wow! I actually did this at some point. Used interceptTouchEvent and stuff. Copy and paste from SO. lol

4

u/tatocaster Aug 10 '20

In a team it's our responsibility to guide newcomers to good coding practice and better technology choices. What I was saying os nowadays you can start learning Coroutines directly and skip AsyncTask, HttpUrlConnection and other beasts. It is much safe and stable place now. Almost everything is provided from Google. I had an opportunity to meet fresh Android students and observe what choices they made. I was happy and also laughing at myself, I was up all night when I was starting 5 years ago, it was a dark, wild valley of Android back then.

1

u/gonemad16 Aug 12 '20

newcomer could mean someone new to android but with plenty of development experience

4

u/3dom Aug 09 '20

Android should have a competent product owner who won't allow half-arsed stuff like spinners auto-triggering user selection event upon filling the options or Room LiveData requiring .distinctUntilChanged method to prevent UI refresh spam or MutableLiveData ignoring data "updates" for the same value (at least for integers and booleans).

There should be an SDK for the present "simple" DK. Maybe Composer may fix this.

2

u/[deleted] Aug 09 '20

Spinner is notoriously bad it seems. As someone who didn't bother to use it, I don't know how bad it is.

Compose.. praying it fixes.

2

u/Zhuinden EpicPandaForce @ SO Aug 09 '20

I think now with RxJava2/RxRelay, Kotlin and Simple-Stack I've got most of my bases covered, but I wouldn't mind some helpers on top of ExploreByTouchHelper for better accessibility support out of the box.

I have a feeling that'll only come in the name of Jetpack Compose, though.

I do wish content creators focused a bit more on creating reactive UIs than on imperatively managing deeply nested state objects. MVI is a distraction, not the holy grail. Typically single-object-state doesn't work well with process death state restoration, so I've always been a bit of a skeptic when it came to these huge __State classes.

Right now, Google described how to use liveData { emitSource(, but people still don't trust LiveData. People should focus less on "purity" and more on getting their code to do exactly what they need.

I also wish the google-developers resources were all reliable, some of them really aren't. (For example, the one that said "don't extend LiveData and so don't use onActive, instead use viewModel.fetchData()" was bad advice, yet people point to it and say "but Google said so").

1

u/[deleted] Aug 09 '20

Thanks for suggestions. Yeah Google resources are go to as first glance. Hope they keep up to date or have an GitHub issue section to suggest edits.

Only seen one implementation of MVI personally https://github.com/mitchtabian/Open-API-Android-App by Mitch Tabian

I believe you reviewed it.

I sincerely hope you do more code reviews of projects : )

1

u/[deleted] Aug 10 '20

Would you care to explain why MVI is a distraction, please?

3

u/Zhuinden EpicPandaForce @ SO Aug 10 '20

Sure. The trick is that some claim it to be an "architecture", it'd be more accurate to label it a "presentation-layer design pattern", but when it all boils down to it, it's mostly a question of "what stuff do I want to create that I may or may not even need for the sake of consistency".

For example, if you follow MVI, then you feel compelled to do the following things:

  • represent synchronous method calls (that could easily be modelled with an interface) from view -> "viewmodel" with an async stream of sealed classes

  • represent all variables that would model the current state as a single class, rather than, well, multiple observable fields.

The idea is that "if it's 1 class, then every update is atomic", but not every aspect of state needs to be bundled with state that can change independently (prime example is error states). It depends on your design when you want to clear the error state, and it depends on your design how you model the absence of data, OR even a data fetch.

The idea of

sealed class DataFetchOperationStatus<T> {
    object Loading: DataFetchOperationStatus()
    data class Error(val exception: Exception): DataFetchOperationStatus()
    data class Success(val value: T): DataFetchOperationStatus()
}

Is not as necessary as it might seem, now you have a multiple-event-emission when you could have just modeled it as a single-event-emission (success/error) which is what suspend fun is in the first place.

In-progress-ness is not necessarily the responsibility of the fetch task itself, which is especially notable if a given task shouldn't be executed at the same time: now the task knowing about itself that it is loading won't prevent the creation of another task, which proves that someone else must know about this state as well - but you don't want to duplicate such statefulness.

TL;DR the "LCE" pattern forces you to need a Flow instead of a suspend fun for questionable gain.

Another TL;DR that I think I diverged from, you can combine multiple ObservableFields together and be notified of any emission, you do not need to explicitly combine everything into a single class for the same effect.

  • MVI, because of its insistence on single-object-state, forces you to have "reducers".

Reducers are a solution to a problem introduced by MVI, namely that you must alter the state only inside a single method, where that single method receives every possible user input or action through a sealed class.

Now you must create a deep copy of your "state" class each time you want to modify a single value, and creating this copy is a manual, imperative process. Unless you're modifying an immutable list, this sort of copying wouldn't be needed. I for one haven't used .copy() in quite a long time.

The whole .copy().copy() craze is caused by MVI. Is the intent of the code clearer than, say, currentName.set("newValue")? I don't think so.

I am fully aware that reducer just represents "current state modified as a result of actions in a state machine", but not all state is actually "the same system", and treating them all as 1 system makes it harder to manage.

Would you care to explain why MVI is a distraction, please?

Because most of the dance you do for MVI is completely unnecessary. ViewModel is already the model. You don't need a new state class to do it. Same issue with Presenters, that's what the Fragment was. "not being able to test the fragment" was less the problem of fragments themselves, in return all we get is ping-pong (shared responsibility in two mutually coupled classes), so trying to wrap it in an incomplete manner (unlike the approach in this repo, complete delegation) is just test-induced design damage. The code won't be modular, it's as coupled as before, just spread to multiple classes and still as Android-bound as any other.

"MVVM" as per Android's recommendation is so far the least intrusive MVC implementation, where you get everything you need to build reactive UIs out of the box (well, apart from a combiner, but you can do that yourself).

MVI is just complexity on top of the things you're already doing, for questionable gain, if any.

2

u/[deleted] Aug 11 '20

Holy duck, that's quite an explanation!

I get it, really well explained. Thank you again for your time, Zhuinden!

1

u/ChrisMBytes Aug 11 '20

There are use cases where MVVM doesn't scale though, and MVI scales much better and can be used in combination with MVVM. Usually those use cases are sharing state between views and having complex state changes like you can have with a recycler view. How many times in the past had I ended up with state changes all over the place in the code base, where one view was mutating the state that another view relied on and lead to bugs that resulted in hack fixes. No one presentation layer design pattern fits all use cases, we should choose the one that best fits the problem we are trying to solve. Same applies to all design patterns, architectural decisions we make. At least that is how I try to do things

1

u/Zhuinden EpicPandaForce @ SO Aug 11 '20

MVI is generally a pattern where ALL state is combined into a SINGLE state machine with no additional subsystems.

I'd rather just have the state machine where the state machine belongs, without combining the other sections of the screen / screens into it.

Mutation is only a problem if it cannot be observed for changes (or those changes are not observed). Although it's true that with mutable data classes, you can easily have unexpected behavior (especially if they're sent as Parcelable, where the original instance is passed through the Bundle, and it only becomes a copy after process death) if your mutation affects "unexpected instances". That's why MVVM is primarily using "observable fields" that hold immutable primitives or read-only collections, and not mutable models.

1

u/ChrisMBytes Aug 11 '20

That's why I said apply it where it is needed. I combine only the state that I need to share and/or the state that is too complex to updated inside the view model. Sharing a view model between views that also exposes state and actions that the other views aren't interested in leads to other problems. If you separate just that shared state into a view model of its own to share between views then what kind of view model is that? I find a contained MVI approach to be much cleaner and scale better

1

u/Zhuinden EpicPandaForce @ SO Aug 11 '20

If you don't want to see everything that the ViewModel holds, then the "View" can define an interface for what it needs, the ViewModel implements it, and now the View can be reused in different flows as well.

Although I think Jetpack ViewModel's factory prevents this from happening without wrapping the ViewModelProvider.Factory with a factory. 😶

This isn't really a characteristic of MVVM on its own, though. If you really shouldn't see the ViewModel as its exact type, then just don't.

(the Jetpack ViewModel is already a misnomer, the name "ScopedModel" would be more accurate).


Technically, what I find a major limitation of most MVI approaches I've seen, is that they give you a base class with a LiveData<State> in it, and this cannot be built asynchronously from combining multiple values.

In fact, it gets worse when I get a BaseFragment with a BF<ViewModel<State>> that explicitly forces BaseFragment to only be usable with THIS specific ViewModel, and THIS specific state class (which is already a combination of multiple systems that must each time be decomposed).

You can make state machines without this sort of dance, but that's what RxJava is. 🤔 Overall, MVI is rigid, combines independent things, and you end up work-arounding its limitations as "part of the pattern".

2

u/ChrisMBytes Aug 11 '20 edited Aug 11 '20

I see your point, I have never went with an MVI library on Android. I implement MVI with Flow or RxJava hot observables, with a state machine, reducer and apply it where I find it is needed. I then inject the relevent reducer to the view model that requires that part of the state and expose the intents. I have encountered use cases where applying just MVVM got too messy, didn't scale ("actual" MVVM - not single screen view models). For example updating a list of complex objects and sharing values of that list with other views... In most cases MVI is not required. MVI in the end is just a way to manage and share state - Redux etc is not what you need to copy to implement MVI

0

u/[deleted] Aug 18 '20

[deleted]

1

u/Zhuinden EpicPandaForce @ SO Aug 18 '20 edited Aug 18 '20

And Redux also tries to fix up problems causing exclusively by Redux, which is why they have to hunt race conditions even in Javascript where there is no actual multi-threading (just asynchronous operations)

We have types so we don't need Redux

0

u/[deleted] Aug 22 '20

[deleted]

1

u/Zhuinden EpicPandaForce @ SO Aug 22 '20

If you need undo behavior, then write it when you need undo behavior.

You don't need to couple all of the application state together into a single deeply nested class in order to achieve command reversal.

Redux creates race conditions in a single threaded environment, that's quite telling.

4

u/ceph12 Aug 10 '20

recently started to work with writing files to external storage and looks like there are a lot of changes there. would love to see a unified solution.

2

u/Suppafly Aug 10 '20

Some tutorials that make sense, where the screenshots actually match what you're seeing and it actually tells you what to install and why.

2

u/tikicaca Aug 10 '20

Improve the lack of "best practices" on stack overflow. Android has improved a lot in the last couple of years, but due to the nature of stack overflow, you will always find the "out dated" way of doing things. Which makes it that much harder for you to get things done.

1

u/MightySeal Aug 10 '20

I wish there were no reason for such insane promotion and PR for google libraries, because:

  1. If you need such promotion, then something went wrong. For instance, square engineers have been producing great OSS for years and they didn't do any kind of promotion besides standard several talks or articles. The design, internals and documentations are usually so good, so you don't have any problems, that makes square oss so popular without any special effort.

  2. This PR and promotion is actually misleading. From my experience those libraries are not intended for large and complex apps. Like, come on, google, every experienced developer knows how to retain object across activity/fragment recreation (and even without reflection, lol), how to handle lifecycle or make proper navigation. Those libs are kinda ok for a newcomer, who isn't yet familiar with android hidden pitfals, but when it comes to something complex those libraries usually cause a lot of problems.