上一页 1 ··· 39 40 41 42 43 44 45 46 47 ··· 186 下一页
摘要: 一,引入lifecycle相关库 1,在项目根目录下的build.gradle中配置脚本,增加: buildscript{ ext { lifecycle = "2.5.1" } } 编辑app下的build.gradle,增加: // lifecycle相关 api "androidx.lifec 阅读全文
posted @ 2025-06-22 12:50 刘宏缔的架构森林 阅读(77) 评论(0) 推荐(0)
摘要: 一,lateinit的作用 1、特性 修饰可变变量:仅用于 var 声明。 手动初始化:开发者需在适当位置(如生命周期回调)显式初始化。 非空类型:只能用于非空类型(如 String、View),不支持基本数据类型(如 Int、Boolean)。 异常风险:访问未初始化的变量会抛出 Uninitia 阅读全文
posted @ 2025-06-22 12:50 刘宏缔的架构森林 阅读(107) 评论(0) 推荐(0)
摘要: 一,代码例子: package com.example.okdemo1.activity import android.os.Bundle import android.widget.Button import androidx.activity.enableEdgeToEdge import an 阅读全文
posted @ 2025-06-22 12:50 刘宏缔的架构森林 阅读(76) 评论(0) 推荐(0)
摘要: 一,两者的区别 主构造函数在类名后面使用constructor关键字声明,并且不能做任何操作,初始化可以在init代码块中进行在构造函数不具有注释符或者默认的可见性修饰符时,constructor关键字可以省略。 辅助构造函数需要使用constructor关键字声明,并且直接或者通过别的辅助函数调用 阅读全文
posted @ 2025-06-22 12:50 刘宏缔的架构森林 阅读(38) 评论(0) 推荐(0)
摘要: 一,data类和普通类的区别 1, 主构造函数必须至少有一个参数,且参数标记为 val 或 var 数据类的主构造函数必须至少有一个参数,并且这些参数必须使用 val 或 var 声明。普通类则没有这样的要求。 2,数据类自动生成了以下方法: toString():生成格式化的字符串表示,如:Use 阅读全文
posted @ 2025-06-22 12:50 刘宏缔的架构森林 阅读(88) 评论(0) 推荐(0)
摘要: 一,代码: package com.example.okdemo1.activity import android.os.Bundle import android.util.Log import android.view.MenuItem import android.widget.Button 阅读全文
posted @ 2025-06-22 12:50 刘宏缔的架构森林 阅读(21) 评论(0) 推荐(0)
摘要: 一,代码 1,application public class MainApplication extends Application { private static MainApplication mApp; private static Context context; public Hash 阅读全文
posted @ 2025-06-14 15:23 刘宏缔的架构森林 阅读(74) 评论(0) 推荐(0)
摘要: 一,代码例子: package com.example.okdemo1.interceptor; import android.content.Context; import android.content.Intent; import android.os.Handler; import andr 阅读全文
posted @ 2025-06-14 15:22 刘宏缔的架构森林 阅读(28) 评论(0) 推荐(0)
摘要: 一,报错信息 Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag 原因: activity继承了context重载了startActivity方法,如 阅读全文
posted @ 2025-06-14 15:22 刘宏缔的架构森林 阅读(280) 评论(0) 推荐(0)
摘要: 一,报错信息: java.lang.RuntimeException: Can't toast on a thread that has not called Looper.prepare() 原因: 原因是Android中不允许在子线程中处理UI。如果要在子线程中处理UI那就要动态转到主线程中执行 阅读全文
posted @ 2025-06-14 15:22 刘宏缔的架构森林 阅读(365) 评论(0) 推荐(0)
上一页 1 ··· 39 40 41 42 43 44 45 46 47 ··· 186 下一页