Thursday, July 31, 2025

Android Storage Techniques for BCA Sem 3 or IT Students

 Prepared By : Prof. Uday Shah (HOD-IT)

Android Storage Techniques

Android Storage Techniques:

  • Shared Preferences

    • SharedPreferences store key-value pairs of primitive data.

    • Ideal for saving small data like user settings, login status, or app configurations.

    • Data is stored persistently in XML format.

    • Accessed using getSharedPreferences() or getPreferences() methods.

    • Data remains intact even when the app is closed.

    • Use putString(), putBoolean(), putInt(), etc. to store data.

    • Use getString(), getBoolean(), etc. to retrieve data.

    • Committing data can be done using apply() or commit().

    • Lightweight and fast, suitable for simple data only.

    • Not recommended for large or complex data structures.

    • Commonly used for storing first-time launch flags or user preferences.

  • Files & Directories

    • Android allows internal and external file storage.

    • Internal storage is private to the app; external is shared (needs permissions).

    • File operations use FileInputStream, FileOutputStream, File classes.

    • Files can store structured or unstructured data in text/binary format.

    • Data written to internal storage is sandboxed per app.

    • Use openFileOutput() and openFileInput() for internal files.

    • External files require runtime permissions (READ_EXTERNAL_STORAGE, etc.).

    • Can store user-generated content like logs, images, or cache.

    • Use directory types like getFilesDir(), getCacheDir(), getExternalFilesDir().

    • Requires good file naming and management practices.

    • Not ideal for relational or structured queries.

  • SQLite Database Connectivity

    • SQLite is a lightweight embedded relational database.

    • Supports standard SQL syntax (INSERT, SELECT, UPDATE, DELETE).

    • Use SQLiteOpenHelper to manage database creation and versioning.

    • Stores structured data in tables and rows.

    • Data persists locally in .db files.

    • Perform CRUD operations using SQLiteDatabase class.

    • Use execSQL() for DDL/DML queries and rawQuery() for SELECT.

    • Helps manage complex relationships with foreign keys and indexes.

    • Ideal for apps like Notes, Inventory, or Contact Management.

    • You need to handle database upgrades using onUpgrade() method.

    • Efficient and scalable for local structured storage.

  • Sharing Data Using Content Providers

    • Content Providers enable sharing data across different apps.

    • Follows a standard URI-based interface (content://authority/path).

    • Supports permissions to restrict or allow external access.

    • Works on tables similar to SQLite and returns Cursor objects.

    • Commonly used for contacts, images, SMS, etc.

    • CRUD operations use ContentResolver methods (insert(), query(), etc.).

    • You must declare your provider in AndroidManifest.xml.

    • Useful for app-to-app communication and modular data sharing.

    • Custom providers can expose your app’s data to others.

    • Follow MIME type conventions and URI patterns properly.

    • Ensures secure and structured access to app data.

Web Services and Android APIs

  • Introduction to JSON (JavaScript Object Notation)

    • JSON is a lightweight data-interchange format.

    • Easy to read and write for both humans and machines.

    • Uses key-value pairs and supports arrays, objects, and nested structures.

    • Commonly used in RESTful APIs to transmit data.

    • Android supports JSON through org.json and third-party libraries like Gson.

    • JSON is language-independent and widely accepted.

    • It helps in syncing app data with a server.

    • Simple to parse using JSONObject and JSONArray.

    • Reduces bandwidth due to compact format.

    • Ideal for mobile applications due to simplicity and speed.

    • Commonly returned in web API responses.

  • JSON Parsing

    • Parsing is the process of converting JSON strings into usable data objects.

    • Use JSONObject for objects and JSONArray for arrays in Android.

    • You can use getString(), getInt() etc. to extract values.

    • Gson and Moshi are popular third-party libraries for parsing.

    • Helps populate UI components dynamically with server data.

    • Handle exceptions like JSONException for robust code.

    • Nested JSON objects can be parsed recursively.

    • Efficient JSON parsing is crucial for performance in networking.

    • Use background threads or AsyncTask (or Kotlin coroutines) for parsing.

    • Proper parsing ensures accurate UI display and data logic.

    • Parsing is often part of API integration processes.

  • Networking API

    • Used for HTTP communication between the app and a remote server.

    • Libraries like Volley, Retrofit, and OkHttp simplify API calls.

    • Supports GET, POST, PUT, DELETE, etc. operations.

    • Requires Internet permission in AndroidManifest.xml.

    • Retrofit supports JSON parsing directly with Gson integration.

    • Can be used to send form data, files, or authentication tokens.

    • Should be used in background threads to avoid UI block.

    • Helps fetch real-time data from online sources.

    • Caching and retries improve API robustness.

    • Retrofit and Volley offer easier error handling and progress tracking.

    • Essential for dynamic mobile applications.

  • Telephony API

    • Enables access to phone-related information and functionality.

    • Use TelephonyManager to get IMEI, SIM, network type, etc.

    • Detect incoming calls, network changes, and service status.

    • Useful in apps like Dialers, Caller ID, or SMS utilities.

    • Requires proper runtime permissions (READ_PHONE_STATE, etc.).

    • Can track call states: IDLE, OFFHOOK, RINGING.

    • PhoneStateListener can be used for tracking changes.

    • Some functionalities restricted from Android 10+ for privacy.

    • Used in enterprise or telecom apps to monitor phone activity.

    • Not all features work on tablets or without SIM cards.

    • Secure usage and permissions handling are a must.

  • Web API

    • Web APIs allow access to remote server data and services.

    • Follow REST architecture, using HTTP methods to operate on resources.

    • Return data in formats like JSON or XML.

    • Can integrate third-party services like weather, maps, or payment gateways.

    • Require API keys or authentication tokens.

    • Retrofit and OkHttp are common tools to consume Web APIs.

    • API responses can be mapped to model classes for easy access.

    • Secure communication uses HTTPS protocol.

    • Error handling and network timeout management is essential.

    • Web APIs allow building scalable and connected mobile apps.

    • Examples: Google Maps API, OpenWeather API, Firebase API.

  • Building and Publishing Application to Online Application Store

    • The process involves creating a signed APK or AAB (Android App Bundle).

    • Apps must pass safety checks like malware scan and policy adherence.

    • Sign your app using keytool and jarsigner or Android Studio's wizard.

    • Google Play Console is the official publishing platform.

    • Requires a developer account and one-time registration fee.

    • Upload the app, screenshots, description, category, and privacy policy.

    • Versioning and release tracks (Alpha, Beta, Production) help in gradual rollout.

    • After submission, Google reviews the app before publishing.

    • Use Play Store’s tools for crash reports, analytics, and user reviews.

    • Updates are submitted using higher version codes.

    • Ensures wide reach and monetization opportunities.


:: Best of Luck ::