小编ges*_*all的帖子

WeakReference无法在Kotlin中运行

我正在AsyncTaskKotlin中实现一个,我需要一个WeakReference用于该方法中运行的回调onPostExecute().我打电话之前设置监听参考execute(),但一旦onPostExecute()被调用,值WeakReferencenull.

class PhotoRotationTask(uri: Uri, filePath: String, resolver: ContentResolver) : AsyncTask<Int, Int, Int>() {
    private var weakRef : WeakReference<OnBitmapProcessedListener>? = null

    var sourceUri : Uri
    var resolver : ContentResolver
    var destPath: String

    init {
        this.sourceUri = uri
        this.resolver = resolver
        this.destPath = filePath
    }

    fun setOnBitmapProcessedListener(listener: OnBitmapProcessedListener){
        weakRef = WeakReference(listener)
        Log.d("RotationTask", "set listener ${weakRef?.get() != null}") //This Log proves that weakRef is initialized before onPostExecute()
    }

    override …
Run Code Online (Sandbox Code Playgroud)

android kotlin

13
推荐指数
1
解决办法
9995
查看次数

不能从java模块调用kotlin模块

我想在java中有一个Android应用程序,但在kotlin中有一个库模块.但是,当我尝试在手机中运行应用程序时,出现错误,说它无法找到我的Kotlin类.这是我的kotlin课程:

    package com.example.mylibrary

    import android.util.Log

    class A {
        fun helloWorld(){
            Log.d("Kotlin", "Hello World!")
        }
    }
Run Code Online (Sandbox Code Playgroud)

和我的kotlin模块的gradle文件:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
buildscript {
    ext.kotlin_version = '0.6.+'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath …
Run Code Online (Sandbox Code Playgroud)

android kotlin

6
推荐指数
1
解决办法
4576
查看次数

标签 统计

android ×2

kotlin ×2