Uploaded January 2023 | Updated November 2026, 3 hours ago
Reading/writing objects with LocalDate data using GSON.
My Videos on GSON
- GSON: Deserializing JSON under explicit control of Named fields: youtu.be/HSuVtkdej8Q
- GSON: Use IntelliJ: youtu.be/Qc9EfiepfWs
- GSON: Array or List as root of JSON: youtu.be/trCGXXNVVYE
- GSON: LocalDate Adapter: youtu.be/j2vWhohxBVA
Reading/writing objects with LocalDate data using GSON.
My Videos on GSON
- GSON: Deserializing JSON under explicit control of Named fields: youtu.be/HSuVtkdej8Q
- GSON: Use IntelliJ: youtu.be/Qc9EfiepfWs
- GSON: Array or List as root of JSON: youtu.be/trCGXXNVVYE
- GSON: LocalDate Adapter: youtu.be/j2vWhohxBVA



![Download XML from a Web Server: Android Programming
Tutorial showing how to download XML data from a sample Google AppEngine web server (http://demoprojectserver1234.appspot.com/) in an Android project. Full Android code below.
// imports omitted due to YouTube space restriction!
// Some code based on content in Android Application Development in 24 hours by Darcey and Conder (2nd ed).
/**
* Demonstrate querying a basic application server for information.
*
*/
public class MainActivity extends Activity {
private static final String TAG = ProjectServerDemo;
public static final String APP_ID = 3fa19507-c746-4dfa-8ded-ec60ef4d30d9;
public static final String SERVER_URL = http://demoprojectserver1234.appspot.com/;
public static final String QUERY_FILE = xmlquery.cgi;
public static final String QUERY_OPTIONS = ?appid= + APP_ID;
public static final String QUERY_URL = SERVER_URL + QUERY_FILE + QUERY_OPTIONS;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick_ClearDisplay(View v) {
TextView textView = (TextView) findViewById(R.id.displayData);
textView.setText();
}
public void onClick_QueryServer(View v) {
Log.i(TAG, Query server...);
AsyncDownloader downloader = new AsyncDownloader();
downloader.execute();
}
private void handleNewRecord(String itemId, String data) {
TextView textView = (TextView) findViewById(R.id.displayData);
String message =
textView.getText().toString() + n +
itemId + : + data;
textView.setText(message);
}
// Inner class for doing background download.
// REVISIT:- Change the [[ to a less than; ]] to a greater than.
// (YouTube wont let you use those characters...)
private class AsyncDownloader extends AsyncTask[[Object, String, Integer]] {
@Override
protected Integer doInBackground(Object... arg0) {
XmlPullParser receivedData = tryDownloadingXmlData();
int recordsFound = tryParsingXmlData(receivedData);
return recordsFound;
}
private XmlPullParser tryDownloadingXmlData() {
try {
Log.i(TAG, Now downloading...);
URL xmlUrl = new URL(QUERY_URL);
XmlPullParser receivedData = XmlPullParserFactory.newInstance().newPullParser();
receivedData.setInput(xmlUrl.openStream(), null);
return receivedData;
} catch (XmlPullParserException e) {
Log.e(TAG, XmlPullParserExecption, e);
} catch (IOException e) {
Log.e(TAG, XmlPullParserExecption, e);
}
return null;
}
private int tryParsingXmlData(XmlPullParser receivedData) {
if (receivedData != null) {
try {
return processReceivedData(receivedData);
} catch (XmlPullParserException e) {
Log.e(TAG, Pull Parser failure, e);
} catch (IOException e) {
Log.e(TAG, IO Exception parsing XML, e);
}
}
return 0;
}
private int processReceivedData(XmlPullParser xmlData) throws XmlPullParserException, IOException {
int recordsFound = 0;
// Find values in the XML records
String appId = ; // Attributes
String itemId = ;
String timeStamp = ;
String data = ; // Text
int eventType = -1;
while (eventType != XmlResourceParser.END_DOCUMENT) {
String tagName = xmlData.getName();
switch (eventType) {
case XmlResourceParser.START_TAG:
// Start of a record, so pull values encoded as attributes.
if (tagName.equals(record)) {
appId = xmlData.getAttributeValue(null, appid);
itemId = xmlData.getAttributeValue(null, itemid);
timeStamp = xmlData.getAttributeValue(null, timestamp);
data = ;
}
break;
// Grab data text (very simple processing)
// NOTE: This could be full XML data to process.
case XmlResourceParser.TEXT:
data += xmlData.getText();
break;
case XmlPullParser.END_TAG:
if (tagName.equals(record)) {
recordsFound++;
publishProgress(appId, itemId, data, timeStamp);
}
break;
}
eventType = xmlData.next();
}
// Handle no data available: Publish an empty event.
if (recordsFound 0) {
publishProgress();
}
Log.i(TAG, Finished processing +recordsFound+ records.);
return recordsFound;
}
@Override
protected void onProgressUpdate(String... values) {
if (values.length 0) {
Log.i(TAG, No data downloaded);
}
if (values.length 4) {
String appId = values[0];
String itemId = values[1];
String data = values[2];
String timeStamp = values[3];
// Log it
Log.i(TAG, AppID: + appId + , Timestamp: + timeStamp);
Log.i(TAG, ItemID: + itemId + , Data: + data);
// Pass it to the application
handleNewRecord(itemId, data);
}
super.onProgressUpdate(values);
}
}
} Download XML from a Web Server: Android Programming](https://i.ytimg.com/vi/kJY4SJ3IgGk/mqdefault.jpg)






