Skip to content

Instantly share code, notes, and snippets.

View zsqw123's full-sized avatar
💖
Keep cute.

zsub zsqw123

💖
Keep cute.
View GitHub Profile
@zsqw123
zsqw123 / issue-1.md
Last active July 10, 2021 09:30
Issue-1 kotlin on Android 5.0 constructor bug

loge:

java.lang.NoSuchMethodError: No direct method <init>(Ljava/lang/String;Ljava/lang/String;IIIIIILjava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V in class Lcom/zsqw123/mediastore/read/ImageRead; or its super classes (declaration of 'com.zsqw123.mediastore.read.ImageRead' appears in /data/app/com.zsqw123.mediastore-2/base.apk:classes2.dex)

code:

class ImageRead(var name: String = "")
@zsqw123
zsqw123 / learn-1-String.format.md
Created July 11, 2021 05:01
learn-1-String.format

原文: String.format()详细用法 (juejin.cn)

转换符 详细说明 示例
%s 字符串类型 “喜欢请收藏”
%c 字符类型 ‘m’
%b 布尔类型 true
%d 整数类型(十进制) 88
%x 整数类型(十六进制) FF
%o 整数类型(八进制) 77
@zsqw123
zsqw123 / learn-2-NetCallback.kt
Last active October 4, 2021 08:34
网络监听回调
import android.app.Application
import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.os.Handler
import android.os.Looper
import android.util.SparseArray
import androidx.annotation.IntDef
@zsqw123
zsqw123 / ExtensionValueDelegates.kt
Last active October 4, 2021 13:20
kotlin 扩展属性 set 方法无法使用 feild 处理办法
import kotlin.reflect.KProperty
/**
* this will be used:
* 1. before getValue return.
* 2. before setValue to change the value.
*/
typealias ValueIntercepter<ValType> = (originValue: ValType) -> ValType
fun <ValType : Any?> exVar(
@zsqw123
zsqw123 / new-kotlin 坑书.md
Last active October 4, 2021 13:46
Kotlin 千万别这么写
  1. 严禁使用 lateinit 和 !!
  2. kotlin 函数类型的 toString 方法极慢 避免使用 (test on 1.5.20)
  3. 不要轻易忽略 IDE 给出的警告: Unchecked cast, JVM 运行时的类型擦除很有可能导致不符合预期, 发现这个问题的起因是发现一个泛型函数的泛型类型加 reified 的时候没有 Unchecked cast 警告, 但是没加的时候有, 经过查看字节码发现没加的时候由于类型擦除会直接 cast 变成 Object 类型
@zsqw123
zsqw123 / new-1-ActivityResults.kt
Last active November 23, 2021 10:13
new-1-ActivityResults
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.util.SparseArray
import androidx.activity.ComponentActivity
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultCaller
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.os.bundleOf
public interface Opcodes {
int NOP = 0; // visitInsn 代表什么都不做
int ACONST_NULL = 1; // - 把null推到栈顶
/*
* ICONST系列只能把 -1 ~ 5 推到栈顶,其它int类型,需要使用PUSH系列命令
*/
int ICONST_M1 = 2; // - 把 -1 推到栈顶
int ICONST_0 = 3; // - 把 int 0 推到栈顶
int ICONST_1 = 4; // - 把 int 1 推到栈顶