File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
app/src/main/java/tinker/sample/android/app Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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 /**
You can’t perform that action at this time.
0 commit comments