Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 安卓服务多个服务开通_Java_Android_Service_Schedule_Timertask - Fatal编程技术网

Java 安卓服务多个服务开通

Java 安卓服务多个服务开通,java,android,service,schedule,timertask,Java,Android,Service,Schedule,Timertask,我正在做一个项目,我必须每10秒进行一次同步,我在服务器上接收人们想要同步的内容。将此首选项保存在阵列中,然后在阵列中查看用户首选项(他们想要同步的内容)。如果选择了ID1,则执行log.i() 这给了我一个问题:它每次同步时都会做一个log.i(“启动服务”);+log.i(“大表”)。随着时间的推移,它正在变成这样: 第二次同步: log.i(“启动服务”) log.i(“大张纸!”) log.i(“大张纸!”) 第三次同步: log.i(“启动服务”) log.i(“大张纸!”) log.

我正在做一个项目,我必须每10秒进行一次同步,我在服务器上接收人们想要同步的内容。将此首选项保存在阵列中,然后在阵列中查看用户首选项(他们想要同步的内容)。如果选择了ID1,则执行log.i()

这给了我一个问题:它每次同步时都会做一个log.i(“启动服务”);+log.i(“大表”)。随着时间的推移,它正在变成这样:

第二次同步:
log.i(“启动服务”)
log.i(“大张纸!”)
log.i(“大张纸!”)

第三次同步:
log.i(“启动服务”)
log.i(“大张纸!”)
log.i(“大张纸!”)
log.i(“大张纸!”)

…每次都一样,我可以开多个服务吗

公共类服务扩展服务{

Context context;
Timer t=new Timer();
timertask timertask=new timertask();
database db;
List checksync =new ArrayList();

@Override
public IBinder onBind(Intent arg0) {
    return null;
}

public void onCreate(){
    //Se comienza aqui!
    super.onCreate();
    //Cojemos el contexto del thread de UI
    context=this;
    db=new database(context);
    onStartCommand1();
}

public void onStartCommand1(){
    //Tiempo de sincronización!
    t.schedule(timertask, 0,5000);
    this.stopSelf();
}

public class timertask extends TimerTask{

    public void run() {
        //Comenzamos a ver que està seleccionado y hacemos threads para subirlo al server

        int num=0;
        db.open();
        checksync = db.check();
        db.close();
        int lenght = checksync.size();
        check(lenght,num);
        Log.i("******", "Starting service");
    }

    public void check(int lenght, int num){

        for(int x=0; x < lenght; x++) {

            num = Integer.parseInt(checksync.get(x).toString());

            if (num == 1) {
                // Subir Sms al server.

            } else if (num == 2) {
                // Subir llamadas

            } else if (num == 3) {
                //subir contactos
                Log.i("*********", "Big sheet!");

            } else if (num == 4) {
                // Subir nombre apps

            } else if (num == 5) {
                // Subir localizaciÔøΩn.

            } else if (num == 6) {
                // Subir todo... (MÔøΩs tarde)
            }
        }
    }

}

public void onDestroy(){
    super.onDestroy();
}
语境;
定时器t=新定时器();
timertask timertask=新的timertask();
数据库数据库;
List checksync=new ArrayList();
@凌驾
公共IBinder onBind(意图arg0){
返回null;
}
public void onCreate(){
//谢谢你!
super.onCreate();
//线程的上下文
上下文=这个;
db=新数据库(上下文);
onStartCommand1();
}
公共无效onStartCommand1(){
//蒂恩波·德·辛克罗尼扎翁!
t、 时间表(timertask,05000);
这个。stopSelf();
}
公共类timertask扩展了timertask{
公开募捐{
//Comenzamos是一个服务器上的线程
int num=0;
db.open();
checksync=db.check();
db.close();
int lenght=checksync.size();
检查(长度、数量);
Log.i(“*******”,“启动服务”);
}
公共无效检查(整数长度,整数数量){
对于(int x=0;x

}

嗯,伙计们。。。我们是否在stackoverflow上有官方语言,或者每个人都使用它,因为它对每个人都方便??几个月前,我提议关闭非英语的问题。我想可能是这样(问题太狭隘了)。