This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.myapplication | |
import android.os.Binder | |
import android.os.Bundle | |
import androidx.core.app.BundleCompat | |
import androidx.fragment.app.Fragment | |
import kotlin.properties.ReadWriteProperty | |
import kotlin.reflect.KProperty | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Android 8.0 的Bitmap: | |
创建native层Bitmap,在native堆申请内存。 | |
通过JNI创建java层Bitmap对象,这个对象在java堆中分配内存。 | |
Android 7.0 的Bitmap: | |
通过JNI调用java层创建一个数组 | |
然后创建native层Bitmap,把数组的地址传进去。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SoftReference<Bitmap> 软引用对象 | |
WeakReference<ImageView> 弱引用对象 | |
强引用: 普通变量都属于强引用,比如 private Context context; | |
软引用: SoftReference,在发生OOM之前,垃圾回收器会回收SoftReference引用的对象。 | |
弱引用: WeakReference,发生GC的时候,垃圾回收器会回收WeakReference中的对象。 | |
虚引用: 随时会被回收,没有使用场景。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define LOG_TAG "Bitmap" | |
#include "Bitmap.h" | |
#include "SkBitmap.h" | |
#include "SkPixelRef.h" | |
#include "SkImageEncoder.h" | |
#include "SkImageInfo.h" | |
#include "SkColorPriv.h" | |
#include "GraphicsJNI.h" | |
#include "SkDither.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
当只有一个线程写,其它线程都是读的时候,可以用volatile修饰变量 | |
当多个线程写,那么一般情况下并发不严重的话可以用Synchronized, | |
Synchronized并不是一开始就是重量级锁, | |
在并发不严重的时候,比如只有一个线程访问的时候,是偏向锁; | |
当多个线程访问,但不是同时访问,这时候锁升级为轻量级锁; | |
当多个线程同时访问,这时候升级为重量级锁。 | |
所以在并发不是很严重的情况下,使用Synchronized是可以的。 | |
不过Synchronized有局限性,比如不能设置锁超时,不能通过代码释放锁。 | |
ReentranLock 可以通过代码释放锁,可以设置锁超时。 | |
高并发下,Synchronized、ReentranLock 效率低, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void checkThread() { | |
if (mThread != Thread.currentThread()) { | |
throw new CalledFromWrongThreadException("Only the original thread that created a view hierarchy can touch its views."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.reactivex.Observable | |
import io.reactivex.subjects.PublishSubject | |
import io.reactivex.subjects.Subject | |
/* | |
* @Author: Hasiy | |
* @Date: 2019/12/25 - 14 : 37 | |
* @Description: Android | |
* @Email: Hasiy.jj@gmail.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @Author: hasiy | |
* @Date: 2019/1/12 - 17 : 06 | |
* @LastEditors: hasiy | |
* @LastEditTime: 2019/1/12 - 17 : 06 | |
* @Description: androoid | |
* @Email: hasiy.jj@gmail.com | |
* 程序主入口 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class LiveDataBus { | |
private final Map<String, MutableLiveData<Object>> bus; | |
private LiveDataBus() { | |
bus = new HashMap<>(); | |
} | |
private static class SingletonHolder { | |
private static final LiveDataBus DATA_BUS = new LiveDataBus(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suspend fun <T> Call<T>.holdUp(): T { | |
return suspendCancellableCoroutine { continuation -> | |
continuation.invokeOnCancellation { | |
LogUtil.w("invokeOnCancellation: cancel the request.") | |
LogUtil.toastWarning("请求异常,请检查网络后重试!") | |
cancel() | |
} | |
enqueue(object : Callback<T> { | |
override fun onResponse(call: Call<T>, response: Response<T>) { | |
when (response.isSuccessful) { |
OlderNewer