ECS 189E: Android and iOS fundamentals
The ViewController lifecycle
Sam King
11/19/2019
Administrative
Last time: GCD
This time: ViewController lifecycle
Next week: ???
This is our last technical lecture where I will quiz you
Administrative
One quiz left, will be hard but count the same as the rest
Milestone 2 meetings on Thursday
Administrative
Meetings with mentors -- are they happening?
Please do switch with groups if you can
Administrative
Submitting to the app store, why you should do it
Developer licenses -- we have some available
Process abstraction vs the app abstraction
Process: once your code is running, you run forever
App: the OS can and will kill your app
Why do mobile OSes do this?
Semantics on iOS vs Android are a bit different
iOS will keep all of your in memory state
Android will kill your memory state, but replay an “Intent” so that you can recreate / lookup again whatever you need
Many bugs on Android due to this, more flexible and efficient
iOS is a more natural way to think about it, I think it’s better
private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
protected Long doInBackground(URL... urls) {
int count = urls.length;
long totalSize = 0;
for (int i = 0; i < count; i++) {
totalSize += Downloader.downloadFile(urls[i]);
publishProgress((int) ((i / (float) count) * 100));
// Escape early if cancel() is called
if (isCancelled()) break;
}
return totalSize;
}
… (continued on next page)
protected void onProgressUpdate(Integer... progress) {
setProgressPercent(progress[0]);
}
protected void onPostExecute(Long result) {
showDialog("Downloaded " + result + " bytes");
}
}
// here’s how to create an AsyncTask
new DownloadFilesTask().execute(url1, url2, url3);
Interesting story about AsyncTask