fixed wakelock issues.
authorkfl_614 <kfl_614@163.com>
Tue, 8 Dec 2020 08:20:12 +0000 (16:20 +0800)
committerkfl_614 <kfl_614@163.com>
Tue, 8 Dec 2020 08:20:12 +0000 (16:20 +0800)
app/release/output-metadata.json [new file with mode: 0644]
app/src/main/AndroidManifest.xml
app/src/main/java/com/ic/temperature/MainActivity.kt
app/version_code.properties

diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json
new file mode 100644 (file)
index 0000000..abc08f9
--- /dev/null
@@ -0,0 +1,18 @@
+{
+  "version": 2,
+  "artifactType": {
+    "type": "APK",
+    "kind": "Directory"
+  },
+  "applicationId": "com.ic.temperature",
+  "variantName": "processReleaseResources",
+  "elements": [
+    {
+      "type": "SINGLE",
+      "filters": [],
+      "versionCode": 2,
+      "versionName": "202012081519",
+      "outputFile": "ICL02Temperature_V2_202012081519_release.apk"
+    }
+  ]
+}
\ No newline at end of file
index d435d63..6f8964b 100644 (file)
@@ -16,7 +16,6 @@
         <activity android:name=".MainActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
-
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
index 0ddaa1f..0c0e822 100644 (file)
@@ -1,6 +1,5 @@
 package com.ic.temperature
 
-import android.annotation.SuppressLint
 import android.content.Context
 import android.os.Bundle
 import android.os.PowerManager
@@ -44,26 +43,34 @@ class MainActivity : AppCompatActivity() {
         initWakeLock()
     }
 
-    private val wakeLock by lazy {
-        val powerManager: PowerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
-        powerManager.newWakeLock(
-            PowerManager.ACQUIRE_CAUSES_WAKEUP or PowerManager.SCREEN_DIM_WAKE_LOCK,
-            "ic:temperatureWakeLock"
-        )
-    }
+    private var wakeLock: PowerManager.WakeLock? = null
+
 
-    @SuppressLint("InvalidWakeLockTag")
     private fun initWakeLock() {
-        wakeLock.acquire(10 * 60)
+        val powerManager: PowerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
+        if (wakeLock == null) {
+            wakeLock = powerManager.newWakeLock(
+                PowerManager.ACQUIRE_CAUSES_WAKEUP or PowerManager.SCREEN_DIM_WAKE_LOCK,
+                "ic:temperatureWakeLock"
+            )
+            wakeLock?.setReferenceCounted(false)
+        }
+        wakeLock?.acquire(10 * 60)
     }
 
-    override fun onDestroy() {
-        super.onDestroy()
+    override fun onPause() {
+        super.onPause()
+        println("onPause...")
         releaseWakeLock()
     }
 
     private fun releaseWakeLock() {
-        wakeLock.release()
+        try {
+            wakeLock?.release()
+            wakeLock = null
+        } catch (e: Exception) {
+            e.printStackTrace()
+        }
     }
 
     /**
index 4bb9657..918912e 100644 (file)
@@ -1,2 +1,2 @@
-#Fri Dec 04 16:57:57 CST 2020
-VERSION_CODE=1
+#Tue Dec 08 15:19:45 CST 2020
+VERSION_CODE=2