android 计时器服务,android-带计时器的服务调用另一个服务

我正在使用Service管理服务器到客户端以及客户端到服务器的数据.在登录后,我打电话给一个服务:

context.startService(new Intent(LoginActivity.this, CheckAutoSyncReceivingOrder.class));

context.startService(new Intent(LoginActivity.this, CheckAutoSyncSendingOrder.class));

我在以上两个服务中都调用了一个计时器

CheckAutoSyncReceivingOrder服务:

Its calling another service named ReceivingOrderService on Every 1

minute to get updated data from server.

public class CheckAutoSyncReceivingOrder extends Service {

Timer timer;

@Override

public IBinder onBind(Intent arg0) {

// TODO Auto-generated method stub

Log.i(TAG, "CheckAutoSyncReceivingOrder Binding Service...");

return null;

}

@Override

public void onStart(Intent intent, int startId) {

// TODO Auto-generated method stub

if (timer != null) {

timer.cancel();

Log.i(TAG, "RECEIVING OLD TIMER CANCELLED>>>");

}

timer = new Timer();

timer.schedule(new TimerTask() {

@Override

public void run() {

Log.i(TAG, "<<<<<<<<< RECEIVING AUTO SYNC SERVICE <<<<<<<

if (InternetConnection.checkConnection(getApplicationContext())) {

if (getDatabasePath(DatabaseHelper.DATABASE_NAME).exists())

startService(new Intent(

CheckAutoSyncReceivingOrder.this,

ReceivingOrderService.class));

} else {

Log.d(TAG, "Connection not available");

}

}

}, 0, 60000); // 1000*60 = 60000 = 1 minutes

}

@Override

public void onDestroy() {

// TODO Auto-generated method stub

if (timer != null)

timer.cancel();

Log.d(TAG, "Stopping Receiving...");

super.onDestroy();

}

}

CheckAutoSyncSendingOrder服务:

Its calling another service named SendingOrderService on Every 2.5

minute to send updated data to server.

public class CheckAutoSyncSendingOrder extends Service {

Timer timer;

@Override

public void onStart(Intent intent, int startId) {

// TODO Auto-generated method stub

if (timer != null) {

timer.cancel();

Log.i(TAG, "OLD TIMER CANCELLED>>>");

}

timer = new Timer();

timer.schedule(new TimerTask() {

@Override

public void run() {

Log.i(TAG, ">>>>>>>> SENDING AUTO SYNC SERVICE >>>>>>>>");

if (InternetConnection.checkConnection(getApplicationContext())) {

if (getDatabasePath(DatabaseHelper.DATABASE_NAME).exists())

startService(new Intent(CheckAutoSyncSendingOrder.this,

SendingOrderService.class));

} else {

Log.d(TAG, "connection not available");

}

}

}, 0, 150000); // 1000*60 = 60000 = 1 minutes * 2.5 = 2.5 =>Minutes

}

@Override

public void onDestroy() {

// TODO Auto-generated method stub

if (timer != null)

timer.cancel();

Log.d(TAG, "Stopping Sending...");

super.onDestroy();

}

@Override

public IBinder onBind(Intent intent) {

// TODO Auto-generated method stub

return null;

}

这两个活动都将运行,直到Internet关闭. Internet连接可用时,它将自动再次呼叫.

主要问题是我遇到了问题,同时自动销毁了活动服务调用.

有什么解决方案或方法可以改变同一件事的流量吗?

预先谢谢你.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值