Image for post
Image for post

If you haven’t seen Google’s architecture, you can learn more about it here. Also, if you’re not familiar with ObjectBox, check out this post.

Introduction

The goal with the architecture is to end up with something like this:

Image for post
Image for post

The main difference is that I’ll be using ObjectBox instead of Room. The architecture doesn’t enforce any specific implementations though. You can always swap out the implementation details. I found ObjectBox to be one of the simplest databases, and it allows for reactive queries without depending on RxJava (though you can use RxJava if you want to).

To see the full example, you can find the GitHub repository here. …


Image for post
Image for post

If you’re familiar with libraries like greenDAO or EventBus, you may have heard of the company that created them: greenrobot. If not, I recommend checking them out. In short, they build high quality open source libraries for app developers.

Recently, they have come out with a new library called ObjectBox. It is used to help manage your app’s local data storage. Their older library greenDAO serves the same purpose, but ObjectBox is their next step in local storage solutions. The biggest difference is that ObjectBox does not use SQL at all.

Getting Started

To get started using it, you can check out their gradle setup. Once you have gradle setup, the library is easy to use. Simply create your data model classes as normal, and add the annotation @Entity. …


Image for post
Image for post

If you’re familiar with RelativeLayout, then ConstraintLayout should feel similar to you. ConstraintLayout has much more flexibility though, and performs better than the RelativeLayout. In general, you should always use ConstraintLayout over RelativeLayout.

To add ConstraintLayout to your project, place the following in your build.gradle files:

Before we look at an example of ConstraintLayout, let’s look at an example using RelativeLayout. I want to have a layout that looks like this:

Image for post
Image for post

To accomplish this, here is my RelativeLayout:

Now to do the same with ConstraintLayout, I added the same kind of constraints my RelativeLayout had:

But, the result looked like…


Image for post
Image for post

At Google I/O this year, Google announced a new set of architecture libraries. One of the new components they included is called LiveData. It can be used to help manage propagating data to your views, while respecting the Activity and Fragment lifecycles. Until now, you typically had to manage all of this on your own. Or more commonly, many developers neglected to handle these scenarios at all. This resulted in memory leaks, among other issues.

In the past, I wrote about how to make an event bus with RxJava. I also wrote about how you could send events without the event bus using RxJava and Dagger. I had mentioned that if you’re not careful about managing these subscriptions, it can easily lead to memory leaks. If you have other developers using your code, you don’t want to rely on them knowing exactly how your code works. …


Image for post
Image for post

Do you have an idea for a new website, app, game, etc.? There are a few things you should consider before dedicating the next few years of your life to it.

If you spend a significant amount of time on anything, you may start to feel like it has some inherent value because of that time. Well, it doesn’t. This is known as the sunk cost fallacy. You can’t get your time back, so you feel the need to justify its value. Whether you spent one year or one day on it, the end result is all that matters.

Nobody owes you anything for your hard work. In fact, nobody cares about your effort in the slightest. All they care about is the end product. Do they want it, or not. It’s your responsibility to make a product that people want to buy. If it sells poorly, the only person you can blame is yourself. …


Image for post
Image for post

To get started you need to include the following in your build.gradle file:

Now you can set up your API interface with RxJava Observables, for example:

As you can see above, I can use my own data model and the JSON response will be converted automatically. I can also simply get a JsonObject if I just want to use the JSON myself.

Alternatively, I can set up my own deserializer, like so:

Lastly, here is my API creation with a deserializer for the User added in:

There are many different ways you can use Retrofit, RxJava, and Gson. This example can be used as a starting point, but there is much more you can do with each of these libraries if you need to.

If You Enjoyed Reading, Please Click That Little Heart. If You Want To Read More Like This, Follow Me On Medium. Thanks!

Originally published at piercezaifman.com on June 10, 2017.


Image for post
Image for post

It’s human nature to compare yourself to others. Everybody does it. The problem is that many of us misunderstand what we’re comparing.

For example, you’re looking at Facebook and see that your friend got a new high paying job. This person is the same age as you, but you know they are making significantly more money than you. Why aren’t you doing that well? You may feel like you’ve fallen behind, or that something has gone wrong in your life.

Yet, consider this: you and your friend are different people. You live completely different lives. It’s not as if your friend is a copy of you with a better job. Maybe you’re more athletic than them, or you have more free time to enjoy each day. …


Image for post
Image for post

Another year, another Google IO conference. As usual, there were some interesting announcements regarding Android. As I was watching the conference, I made a list of things I wanted to try out or learn more about.

Kotlin

Having hung out in various Android communities, Kotlin has been something I’ve seen come up more and more frequently lately. I’ve been mostly avoiding it, because it seemed like a fad. Now that I know it’s not going anywhere, and is supported by Google, I feel like I need to give it a shot. …


Image for post
Image for post

Your life is made up of a series of choices. For many of us, having a choice means that there are right and wrong answers. But I don’t think that’s true.

When I was in university, at the end of my third year of a four year program, I had the option to take an extra year to do an internship. I had the choice to either take the extra year or finish my degree earlier. There are benefits and negatives to each option that I considered, and I chose to do an internship. I’ll never know what would have happened if I finished earlier. …


Image for post
Image for post

Let’s take a look at a sample AsyncTask. It will make a network request to a URL and then return whether or not it was successful. For this example I’m using OkHttp, but that part isn’t important.

If you’ve used an AsyncTask before this code should look familiar. Inside the doInBackground method I make a network request to some given URL, and return the result as a Boolean. Then in onPostExecute I could do something with that result.

Now if I want to remove the AsyncTask and replace it with RxJava (and Retrolambda), one solution would look like this:

About

Pierce Zaifman

Freelance Android app developer | I love productivity, creativity, and finding balance | Email me for a quote at pierce@piercezaifman.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store