CampusLearn
← BIT 305 Mobile Application Development

Local Storage, APIs and Device Sensors

Notes

Choosing storage and synchronisation Local storage keeps information on a device so an application can remain useful without continuous connectivity. A relational database stores structured records in related tables, while key-value storage suits small preferences such as a selected language. Android Room provides an abstraction over SQLite for structured persistence. Offline-first design records work locally and synchronises when connectivity returns. Track synchronisation status and define how conflicting edits are resolved. An idempotency key identifies an operation so retrying it does not create duplicate effects. Sensitive information should be minimised, protected and removed according to a documented retention policy. Using services and sensors safely An application programming interface (API) specifies how software exchanges requests and responses. Mobile apps commonly send HTTPS requests and receive structured JavaScript Object Notation (JSON) data. Validate responses, handle authentication expiry and apply bounded retries with increasing delays rather than repeatedly flooding a failing service. Device sensors provide measurements such as acceleration or location, but availability and accuracy vary. Request permissions in context, explain the purpose and provide a fallback when access is denied. Frequent location updates consume battery, so sampling frequency should match the business need instead of collecting continuously without justification. Practical example A Malindi agribusiness cooperative uses an Android collection app while visiting farms. An officer records 40 milk deliveries offline, each with a unique operation identifier. When connectivity returns, 35 uploads receive confirmed acknowledgements and five remain pending. A timeout then causes three confirmed uploads to be retried. With server-side idempotency, the total remains 35 confirmed records rather than increasing to 38. After the remaining five succeed, all 40 are reconciled. If each record contains two kilobytes, the original payload is 40 times 2, or 80 kilobytes before protocol overhead. Location collection is optional when farmers decline permission.

Quiz

1. Which storage choice best fits many structured offline delivery records?

2. What should an idempotency key prevent during retries?

3. Why should an app avoid unnecessary continuous location sampling?

Sign in to submit and securely grade your quiz.