r/androiddev • • 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.

Post image
614 Upvotes

117 comments sorted by

153

u/drabred Mar 15 '19

Rotate the phone ;>

10

u/Chibichuba Mar 15 '19

I'm a bit dense, what do you mean by that?

35

u/Jizzy_Gillespie92 Mar 15 '19

if you haven't separated your business logic out of the UI there's a pretty good chance your app will crash as soon as you rotate the phone due to fragment/activity lifecycles

20

u/Chibichuba Mar 15 '19

I see, I actually had this issue a while back when I was displaying a ProgressDialog, but I believe I've fixed it now. (Although it looks pretty janky in landscape still)

24

u/gabrielfv minSdkVersion 29 Mar 15 '19

Most apps look janky in landscape. Having a big actionbar looks very bad but is the expected by material design, which makes me realize that not even Google care about how things look in landscape mode.

10

u/drabred Mar 15 '19

I'm yet to stumble on a client that wants a landscape mode support. And I've been doing this for almost 6 years now...

8

u/gabrielfv minSdkVersion 29 Mar 15 '19

The one I currently work for explicitly requested the app should be fixed in portrait mode hehe

1

u/drabred Mar 15 '19

Well I've been using Android for a long time and I only ever use landscape for full screen videos and photos lol.

5

u/GreenKotlin Mar 15 '19

What's landscape? xD. 8 years doing this, I even had a client once who requested me to REMOVE landscape support from his app ¯_(ツ)_/¯

1

u/[deleted] Apr 02 '19

I asked some team members to disallow orientation changes, because the code wasn't handling it properly.

2

u/Zhuinden Mar 15 '19

I've had to write an app that was "portrait on phones, landscape on tablets", and otherwise no orientation change pls.

But I can still force apps to be multi-window and then I can still rotate the screen >:)

3

u/geft Mar 15 '19

Especially tablets.

4

u/Camus145 Mar 15 '19

Look into Android Viewmodels, and Android architecture components. MVVM. Those concepts will take you to the next level and solve phone rotation issues.

5

u/Zhuinden Mar 15 '19

Rotation is only 35% of the puzzle, also make sure you check for process death.

5

u/[deleted] Mar 15 '19

Are there any up to date android tutorials, that teach you about everything, about how to create apps, what must be implemented and so on ?

3

u/Chris2112 Mar 15 '19

Google has some of their own, which walk you through creating an app step by step. They're pretty up to date, at least they were a couple years ago

4

u/Chroko Mar 15 '19

Oh you sweet summer child.

Unfortunately "up to date" and "couple of years ago" do not apply to Android in any sense. There's so much thrash in the APIs and best practices as they throw new stuff in on top of the old.

3

u/Zhuinden Mar 15 '19

I mean there is https://developer.android.com/courses/fundamentals-training/toc-v2 but it also has AsyncTaskLoader despite being "new".

1

u/[deleted] Apr 02 '19

Loaders are still quite nice for loading some kinds of data, although I just use LiveData now.

1

u/Zhuinden Apr 02 '19

(Loaders were never nice. There is no need for the onCreateLoader and Bundle args)

0

u/Chris2112 Mar 15 '19

I never implied that... Maybe try reading a little more clearly next time. All I said was I haven't taken a look in a couple years but it was pretty up to date then. I imagine it still is

3

u/Jizzy_Gillespie92 Mar 15 '19

if you already know at least some Java or Kotlin, then Google Codelabs are relatively up to date and is a decent starting point to dip your toes in

2

u/[deleted] Mar 15 '19

I would HIGHLY recommend just going straight to the Google Developer docs. They can be a bit overwhelming at times if you take on too much, but the information is solid and generally pretty easy to digest.

The issue I've seen with third party tutorials is that they are usually based on slightly out of date practices (not always though). Shit just changes all the time, so I prefer to stick to the source documentation.

Unfortunately, I find some companies have really shitty source documentation, but not Google :) just be patient when digging around. I found that I would often be dancing around the topic I needed for a while before actually finding what I needed (but the info was always there "somewhere")

Do keep in mind that, as a result of Google's pissing match with Oracle, that they definitely promote Kotlin samples. So that might be an issue if you wanna learn the newest stuff using Java, but they generally have a toggle to see Kotlin v Java implementations.

tl;dr - use the Google docs to learn proper Android conventions.

1

u/the_real_uncle_Rico Mar 15 '19

I'm going through one I find on udemy that is relatively up to date

6

u/[deleted] Mar 15 '19

[removed] — view removed comment

11

u/Zhuinden Mar 15 '19

I think it's half the fun of Android development.

If it works, you did a good job!

If it doesn't work, then you forgot to think of something essential and should fix it.

4

u/yaaaaayPancakes Mar 15 '19

Lord, aren't you right.

When we started development on our app, this conversation happened:

Me - "we're going to support rotation, right?"

UX/Product - "No, can't we just lock in portrait?"

Me - "Well, we're going to support rotation, regardless of what you think"

UX/Product - "Why?"

Me - "Because it's the easiest way to trip a configuration change"

(5 min convo of me explaining why if you don't support config change from the jump you are fucked in the long run)

UX/Product - "Fine, but we don't really care"

Now, if I could only get my QA guys to actually test rotation...my stuff works. The new guy who came from iOS, his stuff not so much. He doesn't get it.

2

u/Zhuinden Mar 15 '19

Yeah I know what you mean. We lock orientation to portrait and sometimes I forget to check for bugs on given screens after process death because "ok this used to work clearly I didn't mess up anything that would have broken it".

I tend to be so angry at myself when I do something silly like accessing a lateinit property from a property setter from onRestoreInstanceState by accident after process death even though it's not initialized yet. ¬¬

Honestly maybe rotation should be enabled only for debug builds or something. But it's fair that they don't want to design for landscape, sometimes the landscape design just begs for a grid instead of linear and it gets more complicated. Alas, we'll eventually need to be more responsive anyway.

4

u/yaaaaayPancakes Mar 15 '19

I've just taken it upon myself to make sure it doesn't look like total crap in landscape, since they "don't care". Good enough for me, and makes testing config change easy enough.

Well, that is if I could get others to actually test their work...

54

u/That1guy17 Mar 15 '19

Let him have hope...

1

u/ScienceAndRock Mar 15 '19

I bet he blocked the orientation

72

u/[deleted] Mar 15 '19

[removed] — view removed comment

24

u/drabred Mar 15 '19

That's the easy way out. For the WEAK....

And configuration change can still happen btw ;)

10

u/[deleted] Mar 15 '19

[removed] — view removed comment

10

u/Zhuinden Mar 15 '19

onPause/onResume is generally irrelevant, onStart/onStop is important, and onSaveInstanceState

2

u/[deleted] Mar 15 '19

[removed] — view removed comment

4

u/Zhuinden Mar 15 '19

Well if they ever come out with multi-resume then it'll finally no longer matter.

onPause/onResume is for camera stuff. And I guess "temporarily disabling navigation" because Fragments don't like being started after onSaveInstanceState.

2

u/[deleted] Mar 15 '19

[removed] — view removed comment

2

u/Zhuinden Mar 15 '19

Is your state a preference? 🤔

Although if you're relying on SP then I'm not sure why you're not also relying on [OnSharedPreferenceChangeListener](https://developer.android.com/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener.html#onSharedPreferenceChanged(android.content.SharedPreferences,%20java.lang.String)), it'd make life easier because you can theoretically imitate reactive data sources with it and not have to "eagerly re-fetch in onResume" because you'd always be able to know the latest state because you had registered an observer

1

u/VasiliyZukanov Mar 16 '19

In most cases - yes. I wrote a detailed post about Activity lifecycle that explains why that's the case and when you do need onResume/onPause.

1

u/bernaferrari Mar 16 '19

I just searched in all my projects – not a single place where I needed to override onDestroy().

How do you dispose things?

1

u/[deleted] Apr 02 '19

For most things, yes. onStart and onStop are where your activity/fragment UI become visible/invisible.

11

u/[deleted] Mar 15 '19

"Use MVVM + LiveData" should be the new "screenOrientation="portrait""

0

u/[deleted] Mar 15 '19

[deleted]

0

u/Zhuinden Mar 15 '19

Now put the app in background, terminate the app from Android Studio, then relaunch your app from launcher <3

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

u/Glezcraft Mar 15 '19

I look at my code from yesterday and cringe lol

3

u/busymom0 Mar 15 '19

You just need some sleep then.

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

u/[deleted] 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

u/[deleted] 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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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 implement switchMap by 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

u/Chibichuba Mar 15 '19

Thanks! Hopefully bigger things :)

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

u/GarryLumpkins Apr 05 '19

Thanks! I'll be sure to check it out!

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

u/Chibichuba Mar 15 '19

That's awesome, best wishes to you!

2

u/penskeracin1fan Mar 15 '19

Love the look here also and thank you. Same to you!

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

u/pesto_pasta_polava Mar 15 '19

it's not frowned upon dude, it's the bible!

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

u/[deleted] 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

u/[deleted] Mar 15 '19

You guys are not giving yourself enough credit. I'm sure you can do it!

6

u/[deleted] Mar 15 '19

[removed] — view removed comment

2

u/[deleted] 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

u/[deleted] Apr 02 '19

Just do it! Make your dreams come true! Nothing is impossible!

https://youtu.be/5-sfG8BV8wU

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

u/Zhuinden Mar 15 '19

Good job!

7

u/[deleted] 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

u/[deleted] 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

u/[deleted] 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

u/sqatas Mar 15 '19

High-five!! :D

2

u/[deleted] 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

u/CharaNalaar Mar 15 '19

The settings don't instantly apply?

1

u/ScienceAndRock Mar 15 '19

Love it. Congrats OP

1

u/ikakus Mar 15 '19

Show me the code.

-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

u/[deleted] Mar 26 '19

[deleted]

3

u/Chibichuba Mar 26 '19

I was confused at first haha, but glad mine is working well for you!

0

u/[deleted] 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

u/[deleted] 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

u/[deleted] 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

u/[deleted] 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

u/[deleted] 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

u/Chibichuba Mar 15 '19

I ought to throw my email address and social medias down there too ;)

2

u/[deleted] 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.