积跬步

Just do IT Now.


  • Home

  • Tags

  • Categories

  • Archives

  • Search

Java多线程和线程同步

Posted on 2022-12-19 | In Hencoder

Java多线程和线程同步

进程和线程

  • 进程和线程

    • 操作系统中运行多个软件
    • 一个运行中的软件可能包含多个进程
    • 一个运行中的进程可能包含多个线程
  • CPU线程和操作系统线程

    • CPU线程
      • 多核CPU的每个核各自独立运行,因此每个核一个线程
      • “四核八线程”:CPU硬件方在硬件级别对CPU进行了一核多线程的支持(本质上依然是每个核一个线程)
      • 单核CPU也可以运行多线程操作系统
  • 线程是什么:按代码顺序执行下来,执行完毕就结束的一条线

    • UI线程为什么不会结束?

      因为它在初始化完毕后会执行死循环,循环的内容是刷新界面

Read more »

手写热更新

Posted on 2022-11-24 | In 其他IT

手写热更新

热更新 / 热修复

不安装新版本的软件,直接从⽹络下载新功能模块来对软件进⾏局部更新

Read more »

Android面试总结

Posted on 2022-11-01 | In 678
动画类型?属性动画和补间动画的区别?
StringBuffer和StringBuilder区别?
jvm内存模型?
Read more »

AndroidInterview-Q-A

Posted on 2022-11-01 | In 678

AndroidInterview-Q-A

Java

ClassNotFoundException和NoClassDefFoundError的区别

Read more »

从Retrofit的原理来看HTTP

Posted on 2022-08-31 | In Android

Retrofit使用方法简介

  1. 创建一个interface作为Web Service的请求集合,在里面用注解(Annotation)写入需要配置的请求方法

    1
    2
    3
    4
    public interface GitHubService{
    @GET("users/{user}/repos")
    Call<List<Repo>> listRepos(@Path("user") String user);
    }
  2. 在正式代码里用Retrofit创建出interface的实例

    1
    2
    3
    4
    Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("https://api.github.com/")
    .build();
    GitHubService service = retrofit.create(GitHubService.class);
  3. 调用创建出的Service实例的对应方法,创建出相应的可以用来发起网络请求的Call对象

    1
    Call<List<Repo>> repos = service.listRepos("octocat");
  4. 使用Call.execute()或者Call.enqueue()来发起请求

    1
    repos.enqueue(callback);

Retrofit源码结构总结

Read more »

源码-ComponentActivity的LifecycleOwner

Posted on 2022-08-25 | In Android

原文:https://weread.qq.com/web/reader/d82322e0813ab6e2eg015684

起因:使用Dialog未dismiss时Activity关闭了,导致内存泄露
解决:给Dialog添加生命周期监听

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class TipDialog(context: Context) : Dialog(context), LifecycleObserver {
init {
if (context is ComponentActivity) {
(context as ComponentActivity).lifecycle.addObserver(this)
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.item_tip_dialog)
}
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
private fun onDestroy() {
if (isShowing) {
dismiss()
}
}
}
Read more »

Gradle配置文件拆解

Posted on 2022-08-15 | In Gradle

Gradle配置文件拆解

gradle配置文件里的内容其实“方法调用”,长得类似与json,其实是groovy中的“闭包”(Closure)知识:把方法当作形参传递进去

java中无法把方法当形参传递,有类似的监听(把方法放进一个类中,用匿名内部类的形式把类的对象传进去)(里面的回调就是延后执行的)【=>闭包内容不一定马上执行】

Read more »

工具-Bean检查

Posted on 2022-07-22 | In Android代码片段

bean检查是否含有非静态内部类

gson对非静态内部类(没有默认构造函数)会有问题

作者提了一种检查方法:运行时去匹配,运行时去拿到model对象的包路径下所有的class对象,然后做规则匹配

Read more »

Java-注解

Posted on 2022-06-10 | In Java

Java 注解(Annotation) | 菜鸟教程 (runoob.com)

Java注解(Annotation)又称Java标注,可以通过反射获取标注内容。在编译器生成类文件时,标注可以被嵌入到字节码中。JVM可以保留标注内容,在运行时可以获取到标注内容。

支持自定义Java标注。

Read more »

优雅写法

Posted on 2022-05-13 | In Android代码片段

工具类

优雅关闭流

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.io.Closeable;
import java.io.IOException;

/**
* 说明:关闭流的类
*
* @author shenbh
* time 2021-10-15 15:41
*/
public class CloseableUtil {
public static void close(Closeable closeable){
try {
if (closeable != null){
closeable.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Read more »

Java-BigDecimal运算

Posted on 2022-03-18 | In Java代码片段

BigDecimal加减乘除计算

  • 加法:add()函数
  • 减法:subtract()函数
  • 乘法:multiply()函数
  • 除法:divide()函数
  • 绝对值:abs()函数
Read more »

工具-网络

Posted on 2022-03-16 | In Android代码片段

Android 使用ping判断网络/WIFI连接是否可用

Read more »
<1…567…24>

285 posts
21 categories
44 tags
E-Mail CSDN
0%
© 2018 — 2025 阿炳
Powered by Hexo
|
Theme — NexT.Gemini v5.1.4