r/androiddev • u/Chibichuba • Mar 15 '19
I started learning Java w/ Android exactly 365 days ago, and if this isn't progress, I don't know what is.
31
u/billynomates1 Mar 15 '19
OK but how do you feel about the code? 😄
25
u/Chibichuba Mar 15 '19 edited Mar 15 '19
I took a look at my git history, and it was full of random snippets from StackOverflow and pretty sure I was leaking Contexts all over the place. I'll find a good example and edit this comment in a moment
Edit:
I passed context without a WeakReference into an AsyncTask at some point, so that was probably leaking something. Additionally, here's how I retrieved Reddit's JSON: https://gist.github.com/bwalsh0/42060c233f6a6b693b86899941b03ee8
Retrieving the JSON could've been simplified a bit, and I basically hard-coded the domain check and added ".jpg" at the end. Also, notice how if the domain wasn't one of the two then the a new AsyncTask would execute without end.
Additionally, everything was written one class on top of the default template from Android Studio and amounted to ~800 lines of code. For some reason I did all the lightweight stuff inside AsyncTasks, but handled the wallpaper on the UI thread because I couldn't figure out the classic "non-static/static reference" error.
Bitmap sizes were also left unchecked, which resulted in some terrible SystemUI crashes with massive image files.
48
u/meyerjaw Mar 15 '19
I've be writing code for 15+ years, 10 of which have been professionally. If you don't look at code from 6 months ago and cringe, you haven't learned anything and that's a death sentence for software engineers. Always keep learning and welcome to the craziness!! Congrats
6
u/D00Dy_BuTT Mar 15 '19 edited Jun 12 '23
rob mindless quickest languid clumsy shame square physical axiomatic insurance -- mass edited with https://redact.dev/
4
3
u/yuvz Mar 16 '19
This all sounds pretty advanced for only one year of learning, so kudos!
If you're interested in hunting down memory leaks, I highly recommend Square's wonderful library LeakCanary. For me it's been instrumental in reducing memory leaks and learning more about them, and it's super easy to set up.
Good luck!
1
u/joaquini Mar 15 '19
Are you still using
AsyncTask?7
u/Chibichuba Mar 15 '19
Yeah, but hopefully I'm doing it properly now - unless there are better ways?
6
u/Odinuts Mar 15 '19
Look into RxJava or maybe Coroutines if you're using Kotlin.
0
Mar 15 '19
[deleted]
4
u/Odinuts Mar 15 '19
Oh yeah absolutely. I just mentioned them because OP asked if there were better alternatives.
2
u/Zhuinden Mar 15 '19
Technically I'd rather just post to an executor then post back to the ui thread with a Handler sooner than I'd use AsyncTask.
1
Apr 02 '19
Well it's not neccesssarily bad to use AsyncTasks - you just need to make sure to avoid memory leaks (mainly activity/fragment references) and lifecycle related problems. And avoid chaining AsyncTasks.
The usual code for dealing with those issues tends to be pretty ugly, and it's easy to get them wrong, so if you have to deal with the above then it's better to use RxJava.
1
u/AndyOB Mar 15 '19
I'm self taught as well and am now using RxJava pretty efficiently. Here is how I would move away from Async task if I were you.
Get and learn retrofit with gson ( people will say moshi but for getting started i would just stick with gson since most of the tutorials use it, switch to something else later ). Plenty of great material out there for learning it, it is actually super easy to get into and makes any REST API extremely easy to digest.
Once you're fully comfortable with Retrofit, start using it in conjunction with RxJava2. Also plenty of material out there for that. Making simple api requests with retrofit and rxjava2 is an extremely easy way to dive into RxJava2. At first you see no real difference between rxjava2 and retrofit's enqueue but you'll soon run into use cases where rxjava2 begins to shine. (chaining calls with flatmap, remapping data returned into data structures that are better for your use case.. etc...). This is a great introductory to RxJava2. once you have exposure you start seeing problems all over the place that can be solved with RxJava2.
Once comfortable, look into Repository pattern with RxJava2 and MVVM with google's architecture components. Use RxJava2 to communicate between your ViewModel and your Repository and use LiveData to communicate between your ViewModel and your View. Plenty of material out there to learn about that.
Once you're comfortable with everything above, look into Dagger2 for creating your retrofit instances, okhttp3 client (if needed), injecting retrofit instance to your repository, and injecting your repository into your viewmodel.
You're awesome now because you have some very solid exposure to some of the most popular libraries for android development. All it takes from here is time and practice.
I'm still pretty new, i'm working professionally now but still pretty junior so if anyone more senior wants to chime in please feel free.
1
u/Zhuinden Mar 15 '19
Use RxJava2 to communicate between your ViewModel and your Repository and use LiveData to communicate between your ViewModel and your View. Plenty of material out there to learn about that.
Most of the worst Rx code I see on Stack Overflow tends to come from that setup, namely because they either misuse Rx, misuse LiveData, or misuse both.
So definitely don't trust every tutorial, most of them probably suck.
Theoretically we could be using a MediatorLiveData / Transformations.switchMap to communicate via LiveData between Repository<->ViewModel, see this sample.
Although I'd definitely understand why one would use internal subscriptions cleared in
onCleared()and just save things over into a MutableLiveData - it's easier to grasp than Mediators for some reason (probably because the callbacks are on UI thread, and people are disheartened by having to implementswitchMapby hand and dispatch to ->io thread).
3
u/kaeawc Mar 15 '19
Congrats! Its inspiring to see others posting the results of their efforts :) here's to the next 365 days
2
3
u/GarryLumpkins Mar 15 '19
Great progress! I haven't started Android Development yet myself but I do have some experience with Java from uni and personal projects. What are some Android specific things you wish you were told when first started? Just one or two if you have the time, I can only imagine how much you've learned over the year lol
3
u/Chibichuba Mar 15 '19
To use third-party/Java libraries more often, and to make use of open source apps! Using libraries helped me not have to rewrite entire methods that have already been written by someone, e.g. I used to calculate/convert time manually and used String functions instead of the hundreds out there already.
Open source apps are great for finding how someone else has done it before, and you can modify it to observe what changes.
1
u/GarryLumpkins Mar 16 '19
Thanks! I've been making a lot of use of libraries lately thanks to Rust's amazing package manager cargo. I feel foolish that I avoided libraries before either because I felt it was too difficult/time consuming to learn new libraries or I felt like I could write something quick that could work just as well. Both of those points are almost never true. Open source is amazing too, I'll probably start looking up similar projects on github and see what I can find.
Were there any beginner tutorials that you found particularly helpful when starting out? Admittedly I haven't searched for many as I was just overwhelmed with the amount of them.
2
u/AloysiusGramonde Apr 05 '19
Not op but I've been learning from a YouTube channel called "Coding in Flow" and find it really useful. I prefer tutorials where the person explains the why instead of just the how.
1
3
u/penskeracin1fan Mar 15 '19
Awesome job OP!! I have been working on an Android app for my capstone project and its finishing up atm! It’s a great feeling looking at your progress!!
2
4
u/topna Mar 15 '19
Awesome. I do Android dev for a living in a company for 2.5 years and I cant see doing this myself :D
2
u/Chibichuba Mar 15 '19
Thanks! I'd love to do it as a living, I'm sure you still have some great knowledge about the industry and such.
I have to give a lot of credit to Stack Overflow though (as frowned upon as it is), it helped me out a lot at the beginning.
9
3
u/AndyOB Mar 15 '19
we would never grow as a society if we didn't learn from the documentation of other's struggles. Never feel bad about copying off of stack overflow, that's how literally everyone learns. Also don't feel like you have to come up with the design yourself either. Most professional positions dont require the developer to design the UX/UI. Use dribbble.com to get some ideas if you want to improve your design.
2
u/Zhuinden Mar 15 '19
You just need to make sure that the things you get from SO aren't blatantly incorrect.
Sometimes you need to double check things from 2014 and before.
0
Mar 15 '19
[deleted]
2
u/Chibichuba Mar 15 '19
Working towards a BS in Electrical Engineering w/ a focus in Machine Intelligence!
Definitely spending a lot of time with the other 3 :)
5
6
Mar 15 '19
[removed] — view removed comment
2
Mar 15 '19
I'm sure you can do it! Personally I'd take the Reddit API library, get a list of subreddits, get a list of posts, filter for images. Then after I confirm that's working I'd make a screen where you pick subreddits, one where you define filters for the images, implement some background job with WorkManager, make a settings screen with the constraints for that job, like shown here.
1
10
u/danbo2468 Mar 15 '19
Great job. I love to see progressions like this. A few days ago I took a look at my first Java Git repo and oh man, it was terrible! 😂
8
7
Mar 15 '19
Great work.
Just one thing that itches me: this floating action button on what appears to be a settings screen. I'd either go for instantly applying the settings whenever changed or an X and a checkmark in the toolbar.
1
Apr 02 '19
The FABs at the bottom, easier to access and tap on. Of course, a bottom action bar/toolbar can be used instead, with the check and X buttons at the bottom.
2
Apr 02 '19
Neither is appropriate in my opinion. And I'm not sure I've ever seen a bottom toolbar with check and X buttons, at most I can imagine a bottom sheet. But clearly the default way here would be to not have an Apply button in the first place, or if you do, simple X and checkmark in the toolbar.
6
u/synthestechsia Mar 15 '19
Congratulations! Someday I also hope I'll make an app from scratch and evolve it so much, it looks great.
2
2
Mar 15 '19
Great job! Congrats!
What about kotlin, are you considering it?
It is pretty easy to learn and it's very concise.
2
1
1
-5
u/knooli Mar 15 '19
So I have had experience with flutter, java, and kotlin. I find that flutter is the most efficient for developing uis, java is probably one of the best to do more complicated systems and kotlin is the most "clean" code to write. All of them have their benefits and drawbacks, but recently flutter has been on the rise and sometime this year it should start supporting a single code base for multiple platforms (non-mobile), and that is AWESOME!
4
u/HyperSunbro Mar 15 '19
Kotlin, Java and Flutter aren't really in the same pot. And how is Java better for "complicated systems"?
-2
u/knooli Mar 15 '19
Idk in my mind java just seems to be the most stable out of the three, but I may be wrong!
5
u/SaucyParamecium Mar 15 '19
At this stage stability comes from how you program your software, not really the language itself
2
u/Zhuinden Mar 15 '19
Saving navigation history is definitely not the easiest thing to do in Flutter tho.
-7
u/anagrammatron Mar 15 '19
So you went Java until the end, didn't feel temptation for Kotlin or Flutter?
4
u/Chibichuba Mar 15 '19
I think I honestly was close-minded about alternatives until recently, I started using 3rd party libraries written in Kotlin and it's honestly a beautiful option. I don't know if I'm confident enough to make the switch however, mostly for coding consistency
As for Flutter, I know next to nothing about it minus that it works with both iOS and Android. Since the features of my app aren't possible on un-jailbroken iOS devices, I'm not sure it's worth the effort.
0
u/el_bhm Mar 15 '19
Try writing small classes in Kotlin. Good way to start leaning heavily into SOLID, and Unit tests.
If you are dealing with a lot of null values (and you do not use separate models for I/O and domain), elvis is a godsend.
Kotlin's stream-like api for collections is also cutting down so much boilerplate you'd have in Java.
11
u/Zhuinden Mar 15 '19
There's nothing wrong with Java, while Flutter literally just came out a few months ago.
Dart doesn't even have reflection support on Flutter, very disappointing.
2
u/Kokosnussi Mar 15 '19
why is this being downvoted? On androiddev, isn't this exactly the place to discuss the topic of whether native java, kotlin or maybe even flutter is the best option?
0
0
Mar 15 '19
[deleted]
2
u/Chibichuba Mar 15 '19
That's awesome, how did you capitalize on your work to get yourself into the industry? I'm about 1.5 years away from graduating and I'm trying to go a similar route
0
Apr 02 '19
Make the app open source if possible, put it up on some site (Github, Bitbucket etc.). Create a portfolio (presentation, webpage/website) to showcase your work.
Main thing you need to get interviews is ask for friends/family to recommend you for a job.
0
Mar 15 '19
[deleted]
1
u/Zahloknir Mar 15 '19
As someone learning Android dev, I have a question about the open sourcing. Do you open source your published applications? If so, is it ever a concern someone will just clone your app and upload it to the play store as well?
0
Mar 16 '19
[deleted]
3
u/Chibichuba Mar 16 '19
You're right, my fundamentals probably need some work since I did start from the inside out. To be fair, I had a little over a year of C++ experience from University before starting this so I wasn't going in completely blind.
8
Mar 15 '19
[removed] — view removed comment
5
u/AroXAlpha Mar 15 '19
Not sure if sarcasm... I kinda hide it sometimes so you can see it on overscroll. :-)
1
2
Mar 15 '19
[removed] — view removed comment
4
u/Chibichuba Mar 15 '19
While Muzei is a beautiful app, I feel that Wallpaper Changer for Reddit gives the user more control over exactly where they want their wallpapers to come from, and more catered to Redditors. I always felt Muzei was a little difficult to navigate with options and fine-tuning that weren't in one place, so I tried improve that aspect.
153
u/drabred Mar 15 '19
Rotate the phone ;>