我正在使用Android支持v13中的ViewPager,我想使用滚动到特定项目setCurrentItem(int),但是当我尝试滚动超过2页时应用程序冻结,几秒钟后系统显示ANR窗口.
我试图增加屏幕外屏幕限制setOffscreenPageLimit(2),这样当我试图滚动2页时它没有冻结,但3页也是如此.
我的问题是我的片段非常耗费内存,所以我不想在内存中占用太多.我在支持库v4中使用了相同的代码,但我必须将其更新为v13才能使用NotificationCompat.Builder.addAction(int, CharSequence, PendingIntent).
你们中的任何人都知道可能是什么问题,可能是什么解决方案?
我试图在其他类中调用一个类的静态函数,例如 java,但是在 kotlin 中我无法创建静态函数,我必须创建一个必须在其中定义我的函数的伴侣对象,但是在执行此操作时我不是能够访问父类变量,有什么办法可以在 kotlin 中实现这一点。
class One {
val abcList = ArrayList<String>()
companion object {
fun returnString() {
println(abcList[0]) // not able to access abcList here
}
}
}
class Two {
fun tryPrint() {
One.returnString()
}
}
Run Code Online (Sandbox Code Playgroud)
class One {
val abcList = ArrayList<String>()
companion object {
fun returnString() {
println(abcList[0]) // not able to access abcList here
}
}
}
class Two {
fun tryPrint() {
One.returnString()
}
}
Run Code Online (Sandbox Code Playgroud)
我想像我们在 java 中所做的那样,像第一类的静态函数一样访问有趣的 returnString(),如果有人已经实现了这一点,请帮忙。