Remove nativeX static refs on exit

pull/653/merge
Varun Patil 2023-05-13 17:56:11 -07:00
parent 7f0a75eae2
commit ce3ee760d0
3 changed files with 16 additions and 6 deletions

View File

@ -50,4 +50,10 @@ class MainActivity : AppCompatActivity() {
binding.webview.addJavascriptInterface(mNativeX, "nativex") binding.webview.addJavascriptInterface(mNativeX, "nativex")
binding.webview.loadUrl("http://10.0.2.2:8035/index.php/apps/memories/") binding.webview.loadUrl("http://10.0.2.2:8035/index.php/apps/memories/")
} }
// Cleanup
override fun onDestroy() {
super.onDestroy()
mNativeX.destroy()
}
} }

View File

@ -41,7 +41,11 @@ class NativeX(private val mActivity: AppCompatActivity) {
} }
companion object { companion object {
lateinit var mDlService: DownloadService var mDlService: DownloadService? = null
}
fun destroy() {
mDlService = null
} }
fun handleRequest(request: WebResourceRequest): WebResourceResponse { fun handleRequest(request: WebResourceRequest): WebResourceResponse {
@ -92,7 +96,7 @@ class NativeX(private val mActivity: AppCompatActivity) {
@JavascriptInterface @JavascriptInterface
fun downloadFromUrl(url: String?, filename: String?) { fun downloadFromUrl(url: String?, filename: String?) {
if (url == null || filename == null) return; if (url == null || filename == null) return;
mDlService.queue(url, filename) mDlService!!.queue(url, filename)
} }
@Throws(Exception::class) @Throws(Exception::class)
@ -111,11 +115,11 @@ class NativeX(private val mActivity: AppCompatActivity) {
} else if (path.matches(API.DAY)) { } else if (path.matches(API.DAY)) {
return makeResponse(mQuery.getByDayId(parts[3].toLong())) return makeResponse(mQuery.getByDayId(parts[3].toLong()))
} else if (path.matches(API.SHARE_URL)) { } 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)) { } 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)) { } else if (path.matches(API.SHARE_LOCAL)) {
return makeResponse(mDlService.shareLocal(parts[4].toLong())) return makeResponse(mDlService!!.shareLocal(parts[4].toLong()))
} else { } else {
throw Exception("Not Found") throw Exception("Not Found")
} }

View File

@ -7,6 +7,6 @@ import gallery.memories.NativeX
class DownloadBroadcastReceiver : BroadcastReceiver() { class DownloadBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
NativeX.mDlService.runDownloadCallback(intent) NativeX.mDlService?.runDownloadCallback(intent)
} }
} }