0

Here is my backgroundtask

   private Runnable backgroundTask= new Runnable() {
    @Override
    public void run() {
        try{
            for(int n=0; n<9000; n++) {
                Thread.sleep(1000);

                myHandler.post(foregroundTask);
            }
        } catch(InterruptedException e) {
            e.printStackTrace();
        }
    }
};

And here is my froregroundtask

private Runnable foregroundTask= new Runnable() {
    @Override
    public void run() {
        try{

            konumlar[0]+=1;
            if (konumlar[0]==100)
                konumlar[0]=0;
            if (zaman<100)
            zaman++;
            for (int a=1;a<buses;a++){
                if(zaman>baslangic[a])
                    konumlar[a]+=1;
                if(konumlar[a]==100)
                    konumlar[a]=0;
            }
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
};

This is work good in first time . But after my thread is getting faster. It should be work every 1 second. But it is getting faster. I did not understand that. Also i am using that values some other classes.

@Override 
protected void onStart() { 
      super.onStart(); 
      Thread myThread1 = new Thread(backgroundTask, "backAlias1");     
      myThread1.start(); 
}
lovekrand
  • 47
  • 1
  • 8

1 Answers1

0

Looks like you start couple Threads when coming back to #start Method, as you not stopping the old one.

Kitesurfer
  • 3,438
  • 2
  • 29
  • 47