1.先是bean的问题:
这里喜欢用快捷方法,alt+insert 快速生成bean,遇到一些集合bean默认会生成集成的方式,比如:
class RegionalProtectionBean : ArrayList<RegionalProtectionBeanItem>()
在后面的版本不可用了,因为没有size方法了导致最后改了很多。
2.pendingintent 问题:
java.lang.IllegalArgumentException: com.example.imdemo: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent
PendingIntent pendingIntent;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(this, 123, intent, PendingIntent.FLAG_IMMUTABLE);
} else {
pendingIntent = PendingIntent.getActivity(this, 123, intent, PendingIntent.FLAG_ONE_SHOT);
}
这个方法没有解决我的问题。最后还是修改了runtime的版本号解决问题。
dependencies {
// For Java
implementation 'androidx.work:work-runtime:2.7.1'
// For Kotlin
implementation 'androidx.work:work-runtime-ktx:2.7.1'
}
原来版本是2.5.4 升级到2.7.1才成功,具体的原因不知道,后期再补回。
Java开发中遇到的Bean与PendingIntent问题及解决
本文讨论了在Java开发过程中遇到的两个常见问题:一是使用快捷方式生成Bean时,由于缺少size方法导致的问题;二是处理PendingIntent时遇到的版本兼容性错误。针对这些问题,作者提供了相应的解决方案,包括更新依赖库版本到2.7.1来解决PendingIntent的错误。
444

被折叠的 条评论
为什么被折叠?



