The goal with the architecture is to end up with something like this:
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. …
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.
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
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
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:
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…
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. …
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. …
To get started you need to include the following in your
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:
Originally published at piercezaifman.com on June 10, 2017.
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. …
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.
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. …
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. …
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.