In the Ch6 Earthquake program there's a problem with initiating an internet access from a fragment (EarthquakeListFragment.java)
Specifically, the author says that due to API changes and best practices instead of using a direct call to the xml retrieve/parse routine as in:
Code:
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
int layoutID = android.R.layout.simple_list_item_1;
aa = new ArrayAdapter<Quake>(getActivity(), layoutID , earthquakes);
setListAdapter(aa);
refreshEarthquakes();
You should replace the single line of refreshEarthquakes() with the following. It should open a new thread to call the routine and keep the processing off the main thread:
Code:
Thread t = new Thread(new Runnable() {
public void run() {
refreshEarthquakes();
}
});
t.start();
The problem is twofold.
1) The new thread code he offered doesn't seem to work correctly.
2) If i remove the <uses-sdk ...../> clause from the manifest file the original version (#1 above) works, but including the clause with either version causes the application to crash.
Is there a quick solution that anyone has found to get this to work, or must it use some type of Async Task or service?
thanks