Skip to content

Commit 6798c58

Browse files
committed
1. add fetch tinkerpatch handler
1 parent 2158a3b commit 6798c58

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package tinker.sample.android.app;
2+
3+
import android.os.Handler;
4+
import android.os.Message;
5+
6+
import com.tinkerpatch.sdk.TinkerPatch;
7+
8+
/**
9+
* Created by zhangshaowen on 17/1/8.
10+
*/
11+
12+
public class FetchPatchHandler extends Handler {
13+
public static final long HOUR_INTERVAL = 3600 * 1000;
14+
15+
private long checkInterval;
16+
17+
/**
18+
* 通过handler, 达到按照时间间隔轮训的效果
19+
* @param hour
20+
*/
21+
public void fetchPatchWithInterval(int hour) {
22+
//设置TinkerPatch的时间间隔
23+
TinkerPatch.with().setFetchPatchIntervalByHours(hour);
24+
checkInterval = hour * HOUR_INTERVAL;
25+
//立刻尝试去访问,检查是否有更新
26+
sendEmptyMessage(0);
27+
}
28+
@Override
29+
public void handleMessage(Message msg) {
30+
super.handleMessage(msg);
31+
32+
//这里使用false即可
33+
TinkerPatch.with().fetchPatchUpdate(false);
34+
//每隔一段时间都去访问后台, 增加10分钟的buffer时间
35+
sendEmptyMessageDelayed(0, checkInterval + 10 * 60 * 1000);
36+
}
37+
}

app/src/main/java/tinker/sample/android/app/SampleApplicationLike.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ public void onCreate() {
126126
.setPatchRollbackOnScreenOff(true)
127127
.setPatchRestartOnSrceenOff(true);
128128

129-
TinkerPatch.with().fetchPatchUpdate(false);
129+
//每隔3个小时去访问后台时候有更新,通过handler实现轮训的效果
130+
new FetchPatchHandler().fetchPatchWithInterval(3);
130131
}
131132

132133
/**

0 commit comments

Comments
 (0)