The Android app uses Volley to make a request and receives a response.
Here is a link to the Android's Volley web page and example:
https://developer.android.com/training/volley/index.html
https://developer.android.com/training/volley/simple.html#java
Android API comes with built-in JSON parsing API.
In your app, I am assuming the web-app on the Tomcat server accepts the Android app's request and returns a JSON response - the resonse is received by the Android app.
To parse the response output (which is a JSON
string) and build the data into an ArrayList, the following is the way to code. In this case I am assuming the response JSON string has Earthquake data from a geological website.
Here is some JSON string data to be converted to Java objects and then store them in a List:
"features": [
{
"type": "Feature",
"properties": {
"mag": 4.5,
"place": "150km NW of Nuku`alofa, Tonga",
"time": 1514837288820,
"updated": 1516127564040,
"tz": -720,
"url": "https:\/\/earthquake.usgs.gov\/earthquakes\/eventpage\/us1000byui",
...
"magType": "mb",
"type": "earthquake",
"title": "M 4.5 - 150km NW of Nuku`alofa, Tonga"
In the following code snippet both the classes
JSONObject and
JSONArray are imported as
org.json.*;
The List data
earthquakes is then used in the Android app to, well, list the earthquake details in
ListView. This is how I think the app works.
SCJP 5, OCPJP 7, 8, SCJD 5, SCWCD 4, SCBCD 5, SCJWS 4, IBM OOAD 833 & 834, MongoDB Developer