Professional Documents
Culture Documents
Implementing a
Download Background Service
Android Services
Stefan Tramm
Patrick Bönzli
2008-12-03
Implementing a Download Background Service 2
Agenda
§ the mission
§ customers and usage scenario
§ technical background
§ screenshots
Implementing a Download Background Service 4
Prototype “Jukebox”
Prototype “Jukebox”
§ Android application
§ based on standard ATOM file format (RSS-reader on
steroids)
§ asynchronously updating data in background
§ uses internal SQLite DB and aggressive caching
§ works without network connection (e.g. airplane)
Implementing a Download Background Service 8
Jukebox: Listview
Implementing a Download Background Service 9
Jukebox: Detailview
Implementing a Download Background Service 10
§ Android Services
§ download manager
Implementing
Quality Software
a Download
Engineering
Background Service 11
Goals
Starting Point
Our approach:
Uncoupling network from Activity using a queue.
Implementing a Download Background Service 14
§ AndroidManifest.xml
§ Activities
§ Views
§ Layouts
§ Intents & IntentReceivers
§ Services
§ Notifications
§ ContentProviders
Implementing a Download Background Service 17
Android Toolbox
Android offers:
Architecture Overview
Implementing a Download Background Service 19
Android Service
Services Lifecycle I
Services Lifecycle II
Services IPC
Persistent:
§ files (e.g. flash drive)
§ databases (SQLite), Bonus: offers transactions
§ Android properties
Non-persistent:
§ shared memory
§ network sockets
§ IDL (interface description language) the Android way: AIDL
Implementing a Download Background Service 24
Service definition
public class MyService extends Service {
@Override
protected void onCreate() {
super.onCreate();
Log.i(getClass().getSimpleName(), “Service started.");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.i(getClass().getSimpleName(), “Service stopped.");
}
}
Service start
Interface declaration
interface IRemoteDownloadService {
void startDownload(in Uri uri, String type, IRemoteDownloadServiceCallback cb);
}
Interface implementation
}
Implementing a Download Background Service 27
...
bindService(new Intent("ch.netcetera.REMOTE_DOWNLOAD_SERVICE"), connection,
BIND_AUTO_CREATE);
...
downloader.startDownload(uri, type, downloadCallback);
}
Implementing a Download Background Service 28
Downloading Manager
Implementing a Download Background Service 29
Q&A
Any questions?
Implementing a Download Background Service 31
Conclusions