Real Time Transactions Map: Multi Threading Strategy Daniel Clavijo - ISIS3510-MOBILE-T34/T34-Wiki-SpendiQ GitHub Wiki
Real-Time Transactions Map: Multi-Threading Strategy
Overview
The Transactions Map feature implements a multi-threading strategy to display and update, in real-time, the locations where users have conducted financial transactions. This implementation ensures a smooth and efficient visualization of transactions on the map, differentiating between incomes and expenses using color-coded markers, while avoiding UI blocking.
Purpose
- Enable the visualization of transactions on an interactive map.
- Update information in real-time without impacting the user experience.
- Efficiently handle database read/write operations.
- Ensure data synchronization in scenarios of intermittent connectivity.
Multi-Threading Implementation
Background Operation Queue
A dedicated background queue is implemented to handle:
- Processing of transaction data.
- Read/write operations on the local database.
- Synchronization with Firebase.
- Periodic updates of map markers.
Periodic Updates
- A background timer checks for new transactions every 30 seconds.
- Updates are processed on a secondary thread to avoid UI blocking.
- A caching system is implemented to optimize performance.
State Management
The application maintains distinct threads for:
- UI Thread: Renders the map and markers.
- Background Thread: Handles data processing and synchronization.
- Network Thread: Monitors connectivity and performs Firebase operations.
Benefits of the Strategy
Enhanced Performance
- Responsive UI during heavy operations.
- Efficient background data loading.
- Lower device resource consumption.
Improved User Experience
- Smooth map updates.
- No interface freezing.
- Immediate visual feedback.
Robust Data Handling
- Reliable synchronization.
- Prevention of data loss.
- Efficient memory management.
Use Cases
1. Initial Visualization
- The UI loads immediately.
- Data is loaded asynchronously.
- Markers are progressively updated.
2. Real-Time Updates
- New transactions are detected in the background.
- The UI updates seamlessly.
- Markers are added/removed smoothly.
3. Offline Mode
- Data is stored locally.
- Synchronization occurs in the background.
- The UI reflects connectivity status.
Results
- Significant improvement in application performance.
- Reduced UI freezes and ANRs.
- Increased user satisfaction.
- Better system resource management.
Conclusion
The multi-threading implementation for the Transactions Map feature has enabled the creation of a smooth and efficient user experience while maintaining data integrity and optimizing application performance on both iOS and Android platforms.