1. Asynchronous Simple HTTP On previous week’s assignments we had to do a little ”hack” to get rid of the Android’s security policy. Today we are going to fix that and do things right.
We have to change our code to work asynchronously. In practice this means that we are several thing in parallel. For example, UI is fully functional at the same time when we are loading something from the network. This was not the case on previous week’s assignment. If we would have loaded large files, the UI would be totally jammed during the loading.
There are several ways to solve this problem and today we are going to use AsyncTask to solve it.
Read first AsyncTask documentation: https://developer.android.com/reference/android/os/AsyncTask
Create a new app with same style as previous Simple HTTP and use AsyncTask to load data asynchronously. Remove the StrictMode.ThreadPolicy code to make sure that your load is asynchronous.
2. Stock Monitor Create an app which can be used as stock monitor.
First version of the app should display stock prices of following companies
Company Stock ID Apple AAPL Alphabet (Google) GOOGL Facebook FB Nokia NOK
Use this REST api to get the stock price: https://financialmodelingprep.com/api/company/price/NOK Last parameter in the path will be the stock ID.
Api returns the result in JSON format. You can test it in browser to see the format. We haven’t yet studied elegant ways to parse JSON, we will do it next week. Today you can do JSON parsing (get the price out of the json) with Java’s String methods indexOf and subString. Of course, you can use more elegant json parsers if you wish.
Here’s the example of the UI.
3. Stock Monitor V2 Create a copy of the previous stock monitor app. Modify it in a way that you can add more stocks to the app. See the example below.