Graciously Handle Mobile App Inactivity. Improved Suspension Handling and State Management

Use Case or Problem

As an avid Obsidian user, I’ve encountered challenges when switching to mobile tasks while using Obsidian Sync as a result of mobile OS app suspension. The current handling of app suspension/inactivity often leads to a loss of workflow continuity, causing frustration and a decrease in productivity. I am suggesting a more seamless experience when switching between tasks or resuming work after periods of inactivity.

Proposed Solution

To address this, I suggest the following enhancements to Obsidian’s state management and inactivity handling:

  1. Lifecycle Management: Implement the viewWillDisappear(_:) method to save the current state (open note, scroll position, etc.) when the app enters the background, ensuring user data is preserved.
  2. State Saving and Restoration: Introduce saveCurrentState() and restoreState() methods to persist key state information such as the last opened note and its scroll position, providing a smoother user experience upon app reactivation.
  3. Notification Handling: Register for UIApplication.willResignActiveNotification and UIApplication.didBecomeActiveNotification to respond to app lifecycle events, enabling the app to save its state when entering the background and restore it upon becoming active again.
  4. Background Task Handling: Implement the performBackgroundTask() method to request extra time for essential tasks (e.g., syncing) when the app moves to the background, ensuring that critical operations are completed even if the app is suspended.
  5. State Restoration API: Utilize iOS’s State Restoration API by implementing the UIStateRestoring protocol to save and restore more complex view hierarchies.
  6. Snapshot Generation: Use applicationDidEnterBackground(_:) to create a snapshot of the current UI state, allowing for a seamless visual transition when the app resumes.
  7. Memory Warnings: Respond to didReceiveMemoryWarning() to release non-essential memory, reducing the likelihood of app termination due to system memory pressure.
  8. Optimization for iPad: Enhance multitasking support on iPad by handling size class changes smoothly and maintaining state during transitions between Split View and Slide Over.

Implementing these changes would provide a smoother user experience, enabling the app to restore its previous state quickly and make it feel like it never closed.