From 3cecc1e1219fa787a23fae3e3aacd744b6046fe7 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 12 May 2020 18:15:32 -0700 Subject: [PATCH] Fix up double timer bug --- .../com/danilafe/fencelessgrazing/CollarDetailActivity.kt | 3 +-- .../java/com/danilafe/fencelessgrazing/CollarListActivity.kt | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/danilafe/fencelessgrazing/CollarDetailActivity.kt b/app/src/main/java/com/danilafe/fencelessgrazing/CollarDetailActivity.kt index 95f98b8..2945978 100644 --- a/app/src/main/java/com/danilafe/fencelessgrazing/CollarDetailActivity.kt +++ b/app/src/main/java/com/danilafe/fencelessgrazing/CollarDetailActivity.kt @@ -66,8 +66,6 @@ class CollarDetailActivity : AppCompatActivity() { mapMarker = Marker(map) configureMapPolygon() - refreshTimer.schedule(timerTask { triggerRefresh() }, 0L, 5000L) - boundingBox = Polygon( listOf( CollarPos("20", "20"), @@ -82,6 +80,7 @@ class CollarDetailActivity : AppCompatActivity() { super.onPause() map.onPause() refreshTimer.cancel() + refreshTimer.purge() } override fun onResume() { diff --git a/app/src/main/java/com/danilafe/fencelessgrazing/CollarListActivity.kt b/app/src/main/java/com/danilafe/fencelessgrazing/CollarListActivity.kt index e2d6055..96827cf 100644 --- a/app/src/main/java/com/danilafe/fencelessgrazing/CollarListActivity.kt +++ b/app/src/main/java/com/danilafe/fencelessgrazing/CollarListActivity.kt @@ -3,6 +3,7 @@ package com.danilafe.fencelessgrazing import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.util.Log import android.widget.Toast import androidx.preference.PreferenceManager import androidx.recyclerview.widget.DividerItemDecoration @@ -60,12 +61,15 @@ class CollarListActivity : AppCompatActivity() { map.onResume() refreshTimer = Timer() refreshTimer.schedule(timerTask { triggerRefresh() }, 0L, 5000L) + Log.d("FencelessGrazing", "Should be resumed") } override fun onPause() { super.onPause() map.onPause() refreshTimer.cancel() + refreshTimer.purge() + Log.d("FencelessGrazing", "Should be paused") } private fun triggerRefresh() { @@ -107,7 +111,6 @@ class CollarListActivity : AppCompatActivity() { collarList.adapter = summaryAdapter collarList.layoutManager = layoutManager collarList.addItemDecoration(DividerItemDecoration(collarList.context, layoutManager.orientation)) - refreshTimer.schedule(timerTask { triggerRefresh() }, 0L, 5000L) } private fun updateMapOverlay() {