Africa\'s Talking
Android How To Connect to a RESTFUL API on Android...

How To Connect to a RESTFUL API on Android using Java

-

- Advertisment -

ANDROID NINJAS


Feeling Restful? Well, gas up! Because we are about to Launch. This project is a very simple Android Project aimed at getting you to implement some simple concepts that are very important as far as Android Development is concerned.
In this project, you are going to implement a mobile design of the GADS 2020 Leaderboard.

The mobile App will display the Top 20 learners in the Learning Leaders’ category and Top 20 learners in the Skill IQ Leaders’ category. We are going to Fetch Data From an API(Application Programming Interface) which is hosted on Heroku and Display Data on The Mobile App, sounds interesting? We just getting started. This project is for beginners, intermediate and senior developers who would want to get their hands dirty on  Restful APIs on Android

https://gadsapi.herokuapp.com/    you can get the hosted API here as well as the endpoints we are going to use.

This Project will make you understand

  1. Multi-Activity
  2. View pager
  3. Customizing Toolbar
  4. RecyclerView
  5. Adapters
  6. Making Network Request using Retrofit to an endpoint through a @GET request

what it looks like sending requests through a mobile client and getting response from the api web service

PREREQUISITES

  1. Some Basics on Android mobile development
  2. Basic fundamentals on Java Programming Language
  3. Basic Design Concepts


Photo by Windows / Unsplash

What you need to get started

  1. install android studio
  • you are set to go!

Download Android Studio and SDK tools | Android Developers
<!– hide description –>

LETS GET YOU STARTED….
  1. First, open android studio and create a new project
    First, start a new Android Project by going to File > New project or just tap the Create New Project button on the start page of your Android Studio.
    2. Choose Empty Activity as your project template, then click next.

    Give any name to your project, in my case I named it LeaderBoard for this project and then click finish and wait until the project build successfully.


  1. Now add the following dependencies on the build.gradle(Module :app)

Now when you are done sync the project and wait for build to finish successfully

This is How Your Manifest File Should Look Like remember to add internet permissions


Let’s Get the Layouts done
  1. learning_leaders_fragmet Layout xml file
  2. skill_iq_fragmet Layout xml file

LET’S GET HANDS-ON.

Create a new Java class and name it viewpageradapter this class will assist us is scrolling between two tabs which are skill_iq tab and learning_leaders tab the class extends FragmentPagerAdapter

here is a snippet code…

Next, let’s create a new Package under Java Folder and name it Model then inside Model lets create two Java Classes

1 LeaderBoard java class

Here is a snippet code…
NB make sure you use Serialize


2.SkillIQ Java Class

here is the code snippet…


Now we are going to make two fragments by creating the corresponding Java classes which will extend Fragment

  1. learning_leaders fragment
  2. skill_iq fragment

1.Learning leaders fragment which extends Fragment

here is a code snippet…

2.skill_iq fragment

code snippet..

Great we are almost done hold on for a while!!!

The next Step is making adapters package and creating the two adapters

  1. SkillIQ adapter

code snippet…

2.LearningLeadersAdapter
code snippet…

Let’s create a Service package and inside the package lets create.

  1. ServiceBuilder Class
  2. SkillDataService java interface
  3. LearningLeaderService java interface

1.ServiceBuilder Class

code snippet..


2.SkillIQDataService java interface


code snippet…

3.LeaderBoardDataService

code snippet…

Finally here is where the Magic happens

We are going to make a request inside the respective learning_leaders fragment and skill_iq fragment and set the adapters as well as the Recyclerview. Inside OnViewCreated, we are going to retrieve data from the base URL and display the data

1.First let’s make the request on the learning_leaders fragment inside the OnViewCreated

code snippet…

NB make sure you initialize the RecyclerView, LearningLeadersAdapter and the List as follows inside the learning_leaders fragment
and add a constructor

here is the data that will be displayed

2.Second and final step lets repeat the same process for Skill_iq fragment

code snippet…

Here is what will be displayed

Find the GitHub Repo HERE

HAPPY CODING

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Posts

Building Application using Node.js HTTPS Module and Africa’s Talking SMS API

Introduction For a long time, HTTP (Hypertext Transfer Protocol) was responsible for communication between a client application and a server...

Building an Exam Enrollment and Grade Notification System using Africa’s Talking SMS Shortcode API in Django

Introduction This article explores the application of SMS shortcodes to create transparency and improve the quality of education in learning...

Build a user account management system using USSD and SMS API in Go

Introduction We will be learning how to use both the Africastalking SMS and USSD api by building an application where...

Date & Time Analysis With R

One will learn how to analyse dates and time; reproducing date-related columns from a date and also format dates and time. In application, one will learn how to plot simple and multiple time series data using the R language.
- Advertisement -

Two Factor Authentication With PHP and Africa’s Talking SMS API

Two factor authentication is an additional layer of security used to ensure only authenticated users gain access to an online account. because Passwords are historically weak, and can be easily stolen, it can't alone be the way that users access their accounts.

Building a masked number system using Spring Boot, Android and Voice Apis from Africa’s Talking

Introduction In this walk through we shall be building a platform to enable a hypothetical company have their agents call...
- Advertisement -

You might also likeRELATED
Recommended to you