Jaedye week 10

After two week getting started with Android, I understand the basic workflow as well as simple transition between activities in an Android app. Now comes the interesting story between Activity and Fragment in Android.

When I first started on Android, a lot of tutorial mention about Fragment is the new style but I did not understand the idea of Fragment at that time. Activity is nice, I can make a view and put logic code inside a java class and move around from Activities to Activities, I feel I am fine with it. The need for Fragment arises when I started to implement the Bottom Navigation bar. The problem comes when you want to reuse an element across multiple activity without duplicating code (both logic and view). One example is the Bottom Navigation bar. It doesn’t make sense to just add the code for Navigation bar on every activity, and have it re-rendered in the app. I google and read about this, and I choose to use Fragment. The idea here is that you have one big activity where you put the Toolbar (the top bar) and the Bottom Navigation bar, and everything else is Fragment to hold the content of a specific page in the app. So all the previous pages has already been implemented using Activity, with this approach, I would have to convert all of them into Fragment. But I just leave them like that first, I implement two new pages as Fragment and use the above tactics, hoping to achieve a cleaner app. We shall see how this goes.

The next big thing is I also started to integrating API call to our back end in the Android app using Retrofit library. This takes a while to get things up. We need to create model and use Gson to parse JSON into Java object. And we need to set up retrofit to attach our access-token into API calls for authentication with jwt. After that things went smoothly. I really love Retrofit, highly recommend if you are looking for a library to do API call in Android. With it, making request and parsing response is an ease.

Leave a comment