Add Application-level NetworkMonitor with extensive logging
- Create SimpleNotesApplication class for app-level lifecycle - Move NetworkMonitor from Activity to Application context - Add comprehensive logging to NetworkMonitor (all callbacks) - Add logging to SyncWorker for debugging - Remove NetworkMonitor from MainActivity (now in Application) - Add Battery Optimization dialog in SettingsActivity - Improve Notifications (showSyncInProgress, showSyncSuccess, showSyncError) This should fix background sync issues - NetworkMonitor now runs with Application context instead of Activity context, which should survive when app is in background. Debug with: adb logcat | grep -E 'NetworkMonitor|SyncWorker|SimpleNotesApp'
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package dev.dettmer.simplenotes
|
||||
|
||||
import android.app.Application
|
||||
import android.util.Log
|
||||
import dev.dettmer.simplenotes.sync.NetworkMonitor
|
||||
import dev.dettmer.simplenotes.utils.NotificationHelper
|
||||
|
||||
class SimpleNotesApplication : Application() {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "SimpleNotesApp"
|
||||
}
|
||||
|
||||
private lateinit var networkMonitor: NetworkMonitor
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
Log.d(TAG, "🚀 Application onCreate()")
|
||||
|
||||
// Initialize notification channel
|
||||
NotificationHelper.createNotificationChannel(this)
|
||||
Log.d(TAG, "✅ Notification channel created")
|
||||
|
||||
// Initialize and start NetworkMonitor at application level
|
||||
// CRITICAL: Use applicationContext, not 'this'!
|
||||
networkMonitor = NetworkMonitor(applicationContext)
|
||||
networkMonitor.startMonitoring()
|
||||
|
||||
Log.d(TAG, "✅ NetworkMonitor initialized and started")
|
||||
}
|
||||
|
||||
override fun onTerminate() {
|
||||
super.onTerminate()
|
||||
|
||||
Log.d(TAG, "🛑 Application onTerminate()")
|
||||
|
||||
// Clean up NetworkMonitor when app is terminated
|
||||
networkMonitor.stopMonitoring()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user