Introducing
Your new presentation assistant.
Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.
Trending searches
This week:
Last week:
Next time on
Android Bootcamp:
Google APIs
Android ships with two built in HTTP clients
OKHttp is a third party HTTP client by Square which adds valuable functionality
Android uses a single threaded model
Running long tasks on the UI thread will cause your application to hang so...
For any task that is not UI related you should create a worker thread
There is another way without using Threads directly
AsyncTask
Three options to rejoin onto the UI thread from another thread
2 Rules!
Default HTTP Client
1. Create an interface called TreasureService in the util package
A REST service for the treasures lives at
We're going to get the photos for real this time, off a real web service! Let's prepare the app up to use Retrofit.
http://android-bootcamp-rest-server.herokuapp.com/
Whats wrong here?
1. Inspect the API. The treasure list lives at /treasures
1. Set up the Internet permission in the Manifest
2. Create a class called Properties in the util package to hold app-wide properties, like our service URL.
2. Write a model class for the treasures.
<uses-permission android:name="android.permission.INTERNET" />
At this point you should have real treasures loading into the app. However it will crash when you take a photo - its trying to load the EXIF data from the remote images as if they were a local file. Lets use the co-ordinates provided by the web service.
2. Add retrofit to the build.gradle
http://www.jsonschema2pojo.org
compile 'com.squareup.retrofit:retrofit:1.5.0'
Quite a bit of boilerplate code required here
This will generate the Model class for you.
1. Paste in the treasure JSON
2. Set it to JSON source type
3. ???
4. Generate!
1. Change the 'String mSelectedTreasurePath' variable to
'Treasure mSelectedTreasure.
Could potentially save some code here using apache commons io
2. Write a function which extracts the latitude and longitude from a Treasure object into a Location object
3.Change onActivityResult to use it.
Time to use our shiny new TreasureService client!
Create a new AsyncTask in TreasureListFragment's onViewCreated which fetches the treasure list before creating the adapter.
Almost every mobile app depends on network connectivity to fully function!
1. Adjust TreasureListAdapter to work with List<Treasure> instead of List<String> (don't forget to update the unit test).
2. You'll notice that the image urls returned by the service are relative, not absolute. Add a stub function which, given a Treasure, constructs a full url for the image url.
JSON - JavaScript Object Notation
3. Write a failing unit test for this function, implement the function, and pass!
A data interchange protocol based on a subset of the JavaScript language.
Commonly used in REST APIS for its lightweight and readability.
Sample pictures are SO week 3. Prepare to replace the TreasureLoader with our new TreasureService client.
1. In the TreasureListFragment onCreate, remove the creation of treasureLoader.
2. In its place, use Retrofit to build our TreasureService
1. Construct URL for query
2. Spawn thread / AsyncTask
3. Use HTTP client to download the JSON data
4. Parse JSON data into an object or dictionary
5. Rejoin main thread and use data
A library by Square (again) which generates a client for your REST API.
1. Document REST API
2. Generate client
3. Request into object
design by Dóri Sirály for Prezi