The name “localhost” is just a loopback to your own computer.
1. ACCESSING LOCALHOST ON ANDROID DEVICE.
To access it on your Android Device, you need to find the computer’s IP address.
Go to System preferences/sharing OR just search on right top – remote management Make sure remote management is checked
Go to System preferences/sharing OR just search on right top – remote management
Make sure remote management is checked
Note : MAKE SURE THAT YOUR ANDROID DEVICE AND YOUR MAC/WINDOWS ARE ON THE SAME NETWORK OTHERWISE IT WILL NOT WORK. [EG : SAME WIFI NETWORK].
For Example in the Android code you can use like below and call a webservice that is residing in your local server, i.e your localhost.
2. ACCESSING LOCALHOST ON ANDROID EMULATOR.
You can have the same thing as described above for Android Emulator also as long as they are in same network.
But there are other options too…
You can check it in the post here.