How unit 5 is examined
This unit covers the storage, database, sharing, network, web, telephony and publishing APIs of Android; no past question has been asked recently, so learn each definition and its key points.
Using Android Data and Storage APIs
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>
Definition. <mark>Android provides Shared Preferences, internal storage, external storage and SQLite so that an app can save data persistently.</mark>
Key points.
- Shared Preferences store small key-value pairs such as settings, and are read with
getSharedPreferences()and written through aSharedPreferences.Editorwithcommit()orapply(). - Internal storage keeps private files in the app's own directory using
openFileOutput()andopenFileInput(), and they are deleted when the app is uninstalled. - External storage (SD card or shared storage) holds files that other apps and the user can read, and it needs the
WRITE_EXTERNAL_STORAGEpermission in the manifest on older versions. - SQLite holds structured data in tables, and the choice among the four depends on data size and privacy.
Managing data using SQLite
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>
Definition. <mark>SQLite is a lightweight, open-source, serverless relational database embedded in Android, and each app gets its own private database file.</mark>
Key points.
- The
SQLiteOpenHelperclass creates and upgrades the database through itsonCreate()andonUpgrade()methods. getWritableDatabase()andgetReadableDatabase()return aSQLiteDatabaseobject on which SQL operations are run.insert(),update(),delete()andexecSQL()change data, whilequery()andrawQuery()read it and return aCursor.- A
Cursoris moved withmoveToFirst()andmoveToNext(), and its values are read withgetString()andgetInt(); it must be closed after use.
Sharing Data between Applications with Content Providers
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>
Definition. <mark>A content provider is an Android component that manages a shared set of app data and exposes it to other applications through a URI.</mark>
Key points.
- A provider extends
ContentProviderand implementsquery(),insert(),update(),delete(),getType()andonCreate(). - Other apps reach it through a
ContentResolver, obtained withgetContentResolver(). - Data is addressed by a URI of the form
content://authority/path/id, for examplecontent://contacts/people/5. - The provider must be declared in the manifest with
<provider>and can protect its data with permissions; built-in providers include Contacts, MediaStore and Calendar.
Using Android Networking APIs
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>
Definition. <mark>Networking APIs let an app send and receive data over the internet, using classes such as HttpURLConnection, or libraries such as Volley and Retrofit.</mark>
Key points.
- The app needs the
INTERNETpermission in the manifest, andACCESS_NETWORK_STATEto check connectivity throughConnectivityManager. - Network calls must never run on the main UI thread, otherwise
NetworkOnMainThreadExceptionis thrown, soAsyncTask, threads or a library are used. HttpURLConnectionopens a connection to aURL, and the response is read from itsInputStream.- Retrofit and Volley simplify requests, and JSON responses are parsed with
JSONObjector Gson.
Using Android Web APIs
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>
Definition. <mark>Web APIs let an app consume web services, usually REST over HTTP, and show web content inside the app with the WebView widget.</mark>
Key points.
- A REST API uses HTTP methods GET, POST, PUT and DELETE on URLs, and returns data usually in JSON or XML.
WebViewdisplays a web page inside an activity usingloadUrl("http://..."), and needs theINTERNETpermission.getSettings().setJavaScriptEnabled(true)turns on JavaScript, and aWebViewClientkeeps links opening inside the app rather than in the browser.- Responses from a web API are parsed, then shown in the UI on the main thread.
Using Android Telephony APIs
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>
Definition. <mark>Telephony APIs give an app access to phone features such as calls, SMS and device and network information.</mark>
Key points.
TelephonyManagergives phone state, network operator, device ID and SIM details, and needs theREAD_PHONE_STATEpermission.SmsManager.getDefault().sendTextMessage()sends an SMS and needsSEND_SMS; incoming SMS is received by aBroadcastReceiverwithRECEIVE_SMS.- A call is made with an
Intentof actionACTION_CALLand atel:URI, needingCALL_PHONE, whileACTION_DIALonly opens the dialer and needs no permission. - A
PhoneStateListenerreports call-state changes such as ringing, offhook and idle.
Deploying Android Application to the World
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>
Definition. <mark>Deployment is the process of preparing, signing and publishing a finished app so that users can download it, mostly through Google Play.</mark>
Key points.
- The app is first tested, given a version code and version name in the manifest, and built in release mode with debugging turned off.
- The APK (or app bundle) must be digitally signed with a private key stored in a keystore, and the same key is needed for every update.
- A Google Play developer account is created with a one-time registration fee, then the APK, icon, screenshots and description are uploaded.
- The app can also be distributed by email, a website or other stores, and the Play Store gives updates and statistics.
Last-minute revision
- Android storage options are Shared Preferences, internal storage, external storage and SQLite.
- Shared Preferences hold key-value pairs and are written with an Editor and
commit()orapply(). - SQLite is serverless and private to the app, managed through
SQLiteOpenHelper. - A query returns a
Cursor, which is moved withmoveToNext(). - A content provider shares data through
content://authority/path/idand is accessed by aContentResolver. - Its main methods are query, insert, update, delete and getType.
- Networking needs the
INTERNETpermission and must run off the UI thread. WebViewusesloadUrl(), and JavaScript is enabled through its settings.TelephonyManagerneedsREAD_PHONE_STATE;SmsManagerneedsSEND_SMS.ACTION_CALLplaces a call directly;ACTION_DIALopens the dialer.- A release APK must be signed with a keystore key before publishing on Google Play.
Memory hooks
- Storage four: "PIES", meaning Preferences, Internal, External, SQLite.
- CRUD in a provider: Query, Insert, Update, Delete, plus getType.
- URI shape: content, authority, path, id.
- Network: permission first, thread second.
- Deploy: Test, Version, Sign, Upload.
Coverage checklist
- Using Android Data and Storage APIs: no past questions; covered by definition and key points.
- Managing data using SQLite: no past questions; covered by definition and key points.
- Sharing Data between Applications with Content Providers: no past questions; covered by definition and key points.
- Using Android Networking APIs: no past questions; covered by definition and key points.
- Using Android Web APIs: no past questions; covered by definition and key points.
- Using Android Telephony APIs: no past questions; covered by definition and key points.
- Deploying Android Application to the World: no past questions; covered by definition and key points.