package com.example.android_architecture;
import com.example.android_architecture.core.CustomHandler;
import com.example.android_architecture.core.CustomLooper;
import com.example.android_architecture.core.CustomMessage;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
@Test
public void testHandler(){
// - 子线程中存,子线程中取
new Thread("thread-1"){
@Override
public void run() {
ThreadLocal<String> mThread_A = new ThreadLocal();
mThread_A.set("thread-1");
System.out.println("mThread_A :"+mThread_A.get());
}
}.start();
// - 主线程中存,子线程取
final ThreadLocal<String> mThread_B = new ThreadLocal();
mThread_B.set("thread_B");
new Thread(){
@Override
public void run() {
System.out.println("mThread_B :"+mThread_B.get());
}
}.start();
// - 主线程存,主线程取
ThreadLocal<String> mThread_C = new ThreadLocal();
mThread_C.set("thread_C");
System.out.println("mThread_C :"+mThread_C.get());
CustomLooper.prepare();
CustomHandler customHandler = new CustomHandler(){
@Override
public void handleMessage(CustomMessage msg) {
super.handleMessage(msg);
String mes = (String) msg.obj;
System.out.println("收到消息---》"+ mes);
}
};
CustomMessage customMessage = new CustomMessage();
customMessage.obj = "哈哈,简易 Handler 架构实现";
customHandler.sendMessage(customMessage);
//开始循环获取消息 - 》 分发消息
CustomLooper.loop();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
CustomHandler-master.zip (51个子文件)
CustomHandler-master
gradle.properties 1KB
.DS_Store 8KB
gradle
wrapper
gradle-wrapper.jar 53KB
gradle-wrapper.properties 230B
app
.DS_Store 6KB
src
.DS_Store 6KB
androidTest
java
com
example
android_architecture
ExampleInstrumentedTest.java 735B
test
java
com
example
android_architecture
ExampleUnitTest.java 2KB
main
.DS_Store 6KB
java
.DS_Store 6KB
com
.DS_Store 6KB
example
.DS_Store 6KB
android_architecture
.DS_Store 6KB
core
CustomMessage.java 232B
CustomMessageQueue.java 810B
CustomLooper.java 1KB
CustomHandler.java 1KB
MainActivity.java 592B
res
mipmap-xxhdpi
ic_launcher_round.png 10KB
ic_launcher.png 6KB
mipmap-hdpi
ic_launcher_round.png 5KB
ic_launcher.png 3KB
drawable-v24
ic_launcher_foreground.xml 2KB
mipmap-anydpi-v26
ic_launcher.xml 272B
ic_launcher_round.xml 272B
mipmap-mdpi
ic_launcher_round.png 3KB
ic_launcher.png 2KB
mipmap-xxxhdpi
ic_launcher_round.png 15KB
ic_launcher.png 9KB
mipmap-xhdpi
ic_launcher_round.png 7KB
ic_launcher.png 4KB
values
colors.xml 208B
strings.xml 83B
styles.xml 383B
layout
activity_main.xml 502B
drawable
ic_launcher_background.xml 5KB
AndroidManifest.xml 726B
proguard-rules.pro 751B
build.gradle 738B
.gitignore 7B
LICENSE 11KB
gradlew.bat 2KB
build.gradle 558B
.idea
runConfigurations.xml 564B
vcs.xml 246B
misc.xml 7KB
modules.xml 377B
encodings.xml 135B
settings.gradle 15B
gradlew 5KB
.gitignore 1002B
共 51 条
- 1
资源评论
金戈鐡馬
- 粉丝: 1w+
- 资源: 51
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功