0%

Android进程间通信方式
  1. Bundle
  2. 文件共享
  3. AIDL Android自定义接口语言
  4. Messenger
  5. ContentProvider
  6. Socket
针对这几种IPC通信方式分析一下优缺点

1.Bundle :
简单易用 但是只能传输Bundle支持的对象 常用于四大组件间进程间通信
2.文件共享:
简单易用 但不适合在高并发的情况下 并且读取文件需要时间 不能即时通信 常用于并发程度不高 并且实时性要求不高的情况
3.AIDL :
功能强大 支持一对多并发通信 支持即时通信 但是使用起来比其他的复杂 需要处理好多线程的同步问题 常用于一对多通信 且有RPC 需求的场合(服务端和客户端通信)
4.Messenger :
功能一般 支持一对多串行通信 支持实时通信 但是不能很好处理高并发情况 只能传输Bundle支持的类型 常用于低并发的无RPC需求一对多的场合
5.ContentProvider :
在数据源访问方面功能强大 支持一对多并发操作 可扩展call方法 可以理解为约束版的AIDL 提供CRUD操作和自定义函数 常用于一对多的数据共享场合
6.Socket :
功能强大 可以通过网络传输字节流 支持一对多并发操作 但是实现起来比较麻烦 不支持直接的RPC 常用于网络数据交换

Read more »

Moshi: problem with platform class BigDecimal
1
2
3
4
5
6
7
8
9
10
object BigDecimalAdapter {
@FromJson fun fromJson(string: String) = BigDecimal(string)

@ToJson fun toJson(value: BigDecimal) = value.toString()
}

return Moshi.Builder()
.add(BigDecimalAdapter)
.add(KotlinJsonAdapterFactory())
.build()
Read more »

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* Rxjava zip操作符实现并行请求,统一结果处理
*
* 随堂练习 网络请求 (说明:三个接口请求返回后统一整合并显示)
*/
private void loadPreClassPreviewData() {

Observable<List<PreClassPreviewInfoBean>> observablePreClassPreview =
Observable.create(new Observable.OnSubscribe<List<PreClassPreviewInfoBean>>() {
@Override
public void call(final Subscriber<? super List<PreClassPreviewInfoBean>> subscriber) {
model.loadPreClassPreviewData(selectIds, unitIds, lessonIds, new ILoadDataListener() {
@Override
public void success(YQZYReqType api) {
if (mView != null) {
subscriber.onNext(model.getPreClassPreviewInfoBeanList());
}
}

@Override
public void error(YQZYReqType api, int errorCode, String errorMessage) {
if (mView != null) {
subscriber.onError(new Throwable(errorMessage));
}
}
});
}
}).onErrorReturn(new Func1<Throwable, List<PreClassPreviewInfoBean>>() {
@Override
public List<PreClassPreviewInfoBean> call(Throwable throwable) {
return null;
}
});

Observable<List<ReviewAfterInfoBean>> observableReviewAfter =
Observable.create(new Observable.OnSubscribe<List<ReviewAfterInfoBean>>() {
@Override
public void call(final Subscriber<? super List<ReviewAfterInfoBean>> subscriber) {
model.loadReviewAfterClassData(selectIds, lessonIds, unitIds, clazzLevels, new
ILoadDataListener() {
@Override
public void success(YQZYReqType api) {
if (mView != null) {
subscriber.onNext(model.getReviewAfterInfoBeanList());
}
}

@Override
public void error(YQZYReqType api, int errorCode, String errorMessage) {
if (mView != null) {
subscriber.onError(new Throwable(errorMessage));
}
}
});
}
}).onErrorReturn(new Func1<Throwable, List<ReviewAfterInfoBean>>() {
@Override
public List<ReviewAfterInfoBean> call(Throwable throwable) {
return null;
}
});

Observable<List<HeightWrongInfoBean>> observableHeightWrong =
Observable.create(new Observable.OnSubscribe<List<HeightWrongInfoBean>>() {
@Override
public void call(final Subscriber<? super List<HeightWrongInfoBean>> subscriber) {
model.loadHeightWrongData(selectIds, lessonIds, unitIds, new
ILoadDataListener() {
@Override
public void success(YQZYReqType api) {
if (mView != null) {
subscriber.onNext(model.getHeightWrongInfoBeanList());
}
}

@Override
public void error(YQZYReqType api, int errorCode, String errorMessage) {
if (mView != null) {
subscriber.onError(new Throwable(errorMessage));
}
}
});
}
}).onErrorReturn(new Func1<Throwable, List<HeightWrongInfoBean>>() {
@Override
public List<HeightWrongInfoBean> call(Throwable throwable) {
return null;
}
});

Observable.zip(observablePreClassPreview, observableReviewAfter, observableHeightWrong,
new Func3<List<PreClassPreviewInfoBean>, List<ReviewAfterInfoBean>,
List<HeightWrongInfoBean>, ArrayList<SynPracticeQuestionBean>>() {
@Override
public ArrayList<SynPracticeQuestionBean>
call(List<PreClassPreviewInfoBean> preClassPreviewInfoBeans,
List<ReviewAfterInfoBean> reviewAfterInfoBeans,
List<HeightWrongInfoBean> heightWrongInfoBeans) {

previewAnalyticData();

reviewAnalyticData();

heightWrongData();

//数据整合
baseBean = new ArrayList<SynPracticeQuestionBean>();
if (previewBeanList != null) {
baseBean.addAll(previewBeanList);
}

if (reviewBeanList != null) {
baseBean.addAll(reviewBeanList);
}

if (heightWrongBeanList != null) {
baseBean.addAll(heightWrongBeanList);
}

mView.loadSuccess();
mView.refreshView(baseBean);
return baseBean;
}
}).subscribe();
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* 摩尔投票法
*
* @param nums
* @return
*/
public static int majorityElement(int[] nums) {
int count = 0;
int num = nums[0];
for (int i = 1; i < nums.length; i++) {
if (nums[i] != num) {
count--;
if (count < 0) {
count = 0;
num = nums[i];
}
} else
count++;
}
return num;
}
Read more »

Hexo发表文章设置多个tags:[标签1,标签2,标签3]这种方式,例如[json,fastjson],单个不需要[],直接添加

Hexo发表文章设置多个categories:[分类1,分类2,分类3]这种方式,例如[json,fastjson],单个不需要[],直接添加。第二种方式:

1
2
3
categories:
- json
- fastjson
Read more »

Link:https://github.com/alibaba/fastjson/wiki/SerializeFilter

SerializeFilter是通过编程扩展的方式定制序列化。fastjson支持6种SerializeFilter,用于不同场景的定制序列化。

PropertyPreFilter 根据PropertyName判断是否序列化
PropertyFilter 根据PropertyName和PropertyValue来判断是否序列化
NameFilter 修改Key,如果需要修改Key,process返回值则可
ValueFilter 修改Value
BeforeFilter 序列化时在最前添加内容
AfterFilter 序列化时在最后添加内容

Read more »

项目迁移(Git Mirror 保留原有分支与提交)

1.先克隆老项目的镜像
git clone –mirror old.git (old.git 为老项目的git地址)

2.进入老项目的目录
cd old.git

3.移除老项目的地址替换成新项目
git remote set-url –push origin new.git (new.git 为新项目的git地址)

Read more »

股海十三年在雪球上推荐的书

豆瓣地址:https://www.douban.com/note/715783068/

书中自有黄金屋,在股市上体现得很明显。想靠在股市上赚钱,但是却不看书学习,人云亦云,不会有很大的收获。你不知道买入的原因,也不知道卖出的逻辑,长久以往,拿不住股票。

股海十三年在雪球上推荐的书:

Read more »

这个时候,此时此刻,夜晚的望京,夜晚的北京,我是否是我自己? —北京加班的夜晚

MH.WANG