In my program, I'd like to check for a new version (getting data from HTTP).
The function works perfectly, but I want to have it running in background every X (configurable, one hour, one day, and so on).
So I wrote this code:
    Timer mTimer1 = new Timer();
    PowerManager pm = (PowerManager) this.main.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = this.pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MainActivity.PROGRAM);
    PowerManager.WakeLock wl.acquire();
    TimerTask mTt1 = new TimerTask()
    {
      public void run()
      {
        mTimerHandler.post(new Runnable()
          {
            public void run()
            {
// Do the check...
            }
          });
      }
    };
(since this function is in a separate class NOT deriving from Activity, I passed to the constructor the parent class this.main, so that I can call getSystemService. This Variable is declared as private MainActivity main).
Well, when I start the Timer it checks for new version, then, after an hour (so my settings), I check in the Logs and I see that the thread did not run...
I searched in Internet and I found, that I have to use the PARTIAL_WAKE_LOCK, and I do that...
Any idea, why I have this problem?
Thanks a lot! Luca Bertoncello
 
     
     
     
     
     
    