我的想法是每分钟运行一次。
相反,它大约在20秒左右运行,我不知道为什么。
以下是代码:
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
try{
//Post from Queue & update post
if (NetworkUtils.isConnected()) {
//post from queue
try {
postHelper.postFromQueue();
} catch (IOException e) {
e.printStackTrace();
}
//Update posts
postHelper.updateSolicitations();
}
}
catch (Exception e) {
// TODO: handle exception
}
finally{
//also call the same runnable to call it at regular interval
handler.postDelayed(this, 60000);
}
}
};
我不知道它是否相关,但它是关于MainActivity的创建方法。
答案 0 :(得分:0)
也许您考虑使用ScheduledExecutorService
public static boolean isSorted(double d[]){
boolean sortedAscending = true;
boolean sortedDescending = true;
boolean bool = false;
for (int i = 0; i < d.length-1; i++) {
if(d[i] > d[i+1] && sortedAscending){
sortedAscending = false;
if(bool){
break;
}
bool = true;
}
else if(d[i] < d[i+1]&& sortedDescending){
sortedDescending = false;
if(bool){
break;
}
bool = true;
}
}
return sortedAscending || sortedDescending;
}
答案 1 :(得分:0)
答案 2 :(得分:-4)
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
try{
//Post from Queue & update post
if (NetworkUtils.isConnected()) {
//post from queue
try {
postHelper.postFromQueue();
} catch (IOException e) {
e.printStackTrace();
}
//Update posts
postHelper.updateSolicitations();
}
}
catch (Exception e) {
// TODO: handle exception
}
}
}, 60000);