Android localhost connection using XAMPP / Django server

Sometimes we want to see how our app behaves locally before taking it live.This Tutorial is all about Android localhost connection using XAMPP server. Here, I’ll use my Newscrisp App which i’ve created recently for demonstration. Newscrisp uses Retrofit Library for Networking.

Initially download XAMPP server version according to your operating system in order to setup android localhost. In this tutorial, I will use Mac OS to demonstrate usage of Android Localhost connection.

You can also find the video tutorial on Android Localhost connection using Xampp and Django servers below:

Steps to implement Android Localhost connection using XAMPP Server:

Starting the services:


  1. Open XAMPP application and Start the application by clicking upon start in General Tab.                      android localhost connection - starting xampp server
  2. Later, click START ALL services in Services tab in our Xampp Application.android localhost - starting services required
  3. Then, click ENABLE in Network tab for local host forwarding.android localhost - enabling localhost
  4. Now, click MOUNT to explore the XAMPP folders

android localhost - mount data volumes

After all this, we could find htdocs folder in our XAMPP folder in which we can place our required files in order to navigate from our localhost.

To test our Xampp server, let us try the following link (localhost:8080/dashboard/) and now the url should display the contents of index.html present in htdocs>dashboard folder.

android localhost - displaying dashboard

Now, Create an internal folder, named json in htdocs folder to place our json file. Here i am placing a json file which I have prepared for the tutorial in my json folder.android localhost - my json file

Android Localhost Connection in Android Studio:

  1. Open Android studio to modify our project accordingly
  2. Update the BASE_URL in our code according to the android developer documentation as below android localhost - android documentation network address space

android localhost - base url in our project

3. Since I am using Retrofit library, in order to form complete url, i will create an interface as shown in the image below.android localhost - api interface implementation

4. Now, run the emulator and we could see the articles written in json format are loading in our app from our localhost.android localhost - displaying json from localhost in our emulator

Related Posts