Add LeakCanary.

This commit is contained in:
voussoir 2023-03-28 18:16:53 -07:00
parent ccaec4bf10
commit bac441ad4b
3 changed files with 26 additions and 14 deletions

View file

@ -74,4 +74,6 @@ dependencies {
// OpenStreetMap
implementation 'org.osmdroid:osmdroid-android:6.1.14'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'
}

View file

@ -296,17 +296,22 @@ class MapFragment : Fragment()
}
}
override fun onDestroyView()
{
Log.i("VOUSSOIR", "MapFragment.onDestroy")
super.onDestroyView()
if (database_changed_listener in trackbook.database_changed_listeners)
{
trackbook.database_changed_listeners.remove(database_changed_listener)
}
}
override fun onDestroy()
{
Log.i("VOUSSOIR", "MapFragment.onDestroy")
super.onDestroy()
trackerService.mapfragment = null
requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
if (database_changed_listener in trackbook.database_changed_listeners)
{
trackbook.database_changed_listeners.remove(database_changed_listener)
}
}
private val requestLocationPermissionLauncher = registerForActivityResult(RequestPermission()) { isGranted: Boolean ->
@ -594,10 +599,14 @@ class MapFragment : Fragment()
private val connection = object : ServiceConnection {
override fun onServiceConnected(className: ComponentName, service: IBinder)
{
// get reference to tracker service]
val serviceref = (service as TrackerServiceBinder).service.get()
if (serviceref == null)
{
return
}
bound = true
// get reference to tracker service
val binder = service as TrackerService.LocalBinder
trackerService = binder.service
trackerService = serviceref
trackerService.mapfragment = thismapfragment
// get state of tracking and update button if necessary
trackingState = trackerService.trackingState

View file

@ -57,6 +57,7 @@ import net.voussoir.trkpt.helpers.isRecentEnough
import net.voussoir.trkpt.helpers.iso8601_local
import net.voussoir.trkpt.helpers.random_device_id
import org.osmdroid.util.GeoPoint
import java.lang.ref.WeakReference
import java.util.*
class TrackerService: Service()
@ -70,12 +71,12 @@ class TrackerService: Service()
var currentBestLocation: Location = getDefaultLocation()
var lastCommit: Long = 0
var location_min_time_ms: Long = 0
private val RECENT_TRKPT_COUNT = 7200
private val RECENT_TRKPT_COUNT = 3600
private val DISPLACEMENT_LOCATION_COUNT = 5
lateinit var recent_displacement_locations: Deque<Location>
lateinit var recent_trackpoints_for_mapview: MutableList<GeoPoint>
var bound: Boolean = false
private val binder = LocalBinder()
private val binder = TrackerServiceBinder(this)
private lateinit var notificationManager: NotificationManager
private lateinit var notification_builder: NotificationCompat.Builder
@ -562,8 +563,8 @@ class TrackerService: Service()
}
}
}
inner class LocalBinder : Binder() {
val service: TrackerService = this@TrackerService
}
}
class TrackerServiceBinder(trackerservice: TrackerService) : Binder()
{
val service: WeakReference<TrackerService> = WeakReference(trackerservice)
}