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:
Table of Contents
Steps to implement Android Localhost connection using XAMPP Server:
Starting the services:
- Open XAMPP application and Start the application by clicking upon start in General Tab.
- Later, click START ALL services in Services tab in our Xampp Application.
- Then, click ENABLE in Network tab for local host forwarding.
- Now, click MOUNT to explore the XAMPP folders
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 Connection in Android Studio:
- Open Android studio to modify our project accordingly
- Update the BASE_URL in our code according to the android developer documentation as below