diff --git a/app/src/main/java/gallery/memories/MainActivity.kt b/app/src/main/java/gallery/memories/MainActivity.kt index 19fc569c..881471f3 100644 --- a/app/src/main/java/gallery/memories/MainActivity.kt +++ b/app/src/main/java/gallery/memories/MainActivity.kt @@ -50,4 +50,10 @@ class MainActivity : AppCompatActivity() { binding.webview.addJavascriptInterface(mNativeX, "nativex") binding.webview.loadUrl("http://10.0.2.2:8035/index.php/apps/memories/") } + + // Cleanup + override fun onDestroy() { + super.onDestroy() + mNativeX.destroy() + } } \ No newline at end of file diff --git a/app/src/main/java/gallery/memories/NativeX.kt b/app/src/main/java/gallery/memories/NativeX.kt index bc44ef1c..7ca1813b 100644 --- a/app/src/main/java/gallery/memories/NativeX.kt +++ b/app/src/main/java/gallery/memories/NativeX.kt @@ -41,7 +41,11 @@ class NativeX(private val mActivity: AppCompatActivity) { } companion object { - lateinit var mDlService: DownloadService + var mDlService: DownloadService? = null + } + + fun destroy() { + mDlService = null } fun handleRequest(request: WebResourceRequest): WebResourceResponse { @@ -92,7 +96,7 @@ class NativeX(private val mActivity: AppCompatActivity) { @JavascriptInterface fun downloadFromUrl(url: String?, filename: String?) { if (url == null || filename == null) return; - mDlService.queue(url, filename) + mDlService!!.queue(url, filename) } @Throws(Exception::class) @@ -111,11 +115,11 @@ class NativeX(private val mActivity: AppCompatActivity) { } else if (path.matches(API.DAY)) { return makeResponse(mQuery.getByDayId(parts[3].toLong())) } else if (path.matches(API.SHARE_URL)) { - return makeResponse(mDlService.shareUrl(URLDecoder.decode(parts[4], "UTF-8"))) + return makeResponse(mDlService!!.shareUrl(URLDecoder.decode(parts[4], "UTF-8"))) } else if (path.matches(API.SHARE_BLOB)) { - return makeResponse(mDlService.shareBlobFromUrl(URLDecoder.decode(parts[4], "UTF-8"))) + return makeResponse(mDlService!!.shareBlobFromUrl(URLDecoder.decode(parts[4], "UTF-8"))) } else if (path.matches(API.SHARE_LOCAL)) { - return makeResponse(mDlService.shareLocal(parts[4].toLong())) + return makeResponse(mDlService!!.shareLocal(parts[4].toLong())) } else { throw Exception("Not Found") } diff --git a/app/src/main/java/gallery/memories/service/DownloadBroadcastReceiver.kt b/app/src/main/java/gallery/memories/service/DownloadBroadcastReceiver.kt index ceab44a4..1b0183ae 100644 --- a/app/src/main/java/gallery/memories/service/DownloadBroadcastReceiver.kt +++ b/app/src/main/java/gallery/memories/service/DownloadBroadcastReceiver.kt @@ -7,6 +7,6 @@ import gallery.memories.NativeX class DownloadBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { - NativeX.mDlService.runDownloadCallback(intent) + NativeX.mDlService?.runDownloadCallback(intent) } } \ No newline at end of file