Feature 4.5 Jose David Florez Ruiz - ISIS3510-MOBILE-T34/T34-Wiki-SpendiQ GitHub Wiki

Background Data Fetching Service

Overview

The Background Data Fetching Service is a key feature designed to ensure that users always have the most up-to-date information available, even when going offline. It runs automatically whenever the app is closed, fetching essential data like accounts and offers in the background. This multi-threading feature guarantees efficient performance by handling data synchronization tasks in parallel, without disrupting other operations or affecting the app's responsiveness.

Key Features

1. Ensures Offline Readiness

  • Automatically fetches and updates critical data when the user exits the app.
  • Allows users to access the latest information even without an active internet connection by syncing data in advance.

2. Multi-Threading Architecture

  • Utilizes multi-threading to perform background tasks efficiently.
  • Fetches data for different modules (e.g., accounts and offers) simultaneously, ensuring faster execution and resource optimization.
  • Prevents blocking the main thread, keeping the app responsive and smooth during background operations.

3. Seamless Background Operation

  • Runs as a foreground service to ensure uninterrupted execution, even if the app is no longer active.
  • Operates silently and efficiently in the background without requiring user interaction.

4. Network Awareness

  • Checks for active network connectivity before initiating the data fetch process.
  • Skips the operation if no connection is detected, avoiding unnecessary resource usage.

5. Automatic Termination

  • Stops itself once the data fetching tasks are completed, minimizing battery and system resource consumption.

6. User Transparency

  • Displays a notification while running, informing the user that data is being fetched in the background.
  • Complies with Android’s foreground service requirements, ensuring the process remains user-friendly and secure.

How It Works

Triggering the Service

  • The service starts automatically whenever the user closes the app. This proactive approach ensures that data is always up-to-date before the app is reopened or goes offline.

Multi-Threaded Data Fetching

  • The service uses multiple threads to handle data synchronization tasks in parallel:
    • Accounts Data: Fetches and updates account-related information in the background.
    • Offers Data: Simultaneously retrieves the latest offers and promotional content.
  • This multi-threaded design accelerates the synchronization process and prevents one task from delaying others.

Network Connectivity Check

  • Before fetching data, the service checks for an active internet connection (Wi-Fi or cellular).
  • If no connection is available, the service skips the operation and stops, preserving resources.

Background Execution

  • Runs as a foreground service to maintain operation continuity.
  • Uses coroutines to offload tasks to background threads, ensuring the main thread remains unaffected.

Automatic Termination

  • Once data fetching is completed, the service stops itself automatically.
  • This approach optimizes resource usage and prevents unnecessary battery drain.

Benefits

  • Offline Access: Users always have the latest data available, even without an internet connection.
  • Performance Optimization: Multi-threading ensures fast and efficient data synchronization, reducing wait times.
  • User Convenience: Eliminates the need for manual data refreshes, enhancing the overall user experience.
  • Resource Efficiency: The service runs only when needed and stops automatically, minimizing impact on device performance and battery life.
  • Transparency and Compliance: Keeps users informed through notifications and adheres to Android’s best practices for foreground services.

Use Cases

  1. Offline Preparation: Ensures users can access critical data such as account details and offers while offline, enhancing reliability in low-connectivity scenarios.
  2. Efficient Background Syncing: Updates multiple data sources in parallel, ensuring quick and comprehensive synchronization.
  3. User Experience Enhancement: Automatically updates data without requiring user input, making the app more seamless and user-friendly.