strange Problem related to service

Put your problem here if it does not fit any of the other categories.

strange Problem related to service

Postby Nemat » Thu Oct 08, 2009 12:20 pm

Hi....

I am presently working on services.I am facing a strange problem.I have to start a service on boot completed.First I wrote the code in service:
Code: Select all
public class BackgroundService extends Service{
   /**
     * Delay until first exeution of the Log task.
     */
    private final long mDelay = 0;
    /**
     * Period of the Log task.
     */
    private final long mPeriod = 500;
    /**
     * Log tag for this service.
     */
    private final String LOGTAG = "BootDemoService";
    /**
     * Timer to schedule the service.
     */
    private Timer mTimer;
   
    /**
     * Implementation of the timer task.
     */
    private class LogTask extends TimerTask {
     public void run() {
      Log.i(LOGTAG, "scheduled");
      Log.i("BOOTDEMOPPROCESS", "scheduled111111111");
     }
    }
    private LogTask mLogTask;
   @Override
   public IBinder onBind(Intent intent) {
      // TODO Auto-generated method stub
      return null;
   }
    @Override
    public void onCreate() {
     super.onCreate();
     Log.i(LOGTAG, "created");
     Log.i("BOOTDEMOPPROCESS", "created222222");
    mTimer = new Timer();
     mLogTask = new LogTask();
    }
   
    @Override
    public void onStart(final Intent intent, final int startId) {
     super.onStart(intent, startId);
     Log.i(LOGTAG, "started");
    mTimer.schedule(mLogTask, mDelay, mPeriod);
    }


}


Then I changed this code into the following lines of code:
Code: Select all


public class RunService extends Service{
   
   
   @Override
   public IBinder onBind(Intent intent) {
      // TODO Auto-generated method stub
      return null;
   }
    @Override
    public void onCreate() {
     super.onCreate();
     Log.i("LOGTAG", "created");
     Log.i("BOOTING", "I have created");
   
    }
   
    @Override
    public void onStart(final Intent intent, final int startId) {
     super.onStart(intent, startId);
     Log.i("LOGTAG", "started");
        
    }
   
   
}



Now that I have changed the code and removed all the lines related to Timer but I still got "scheduled" and "scheduled111111" writen into the log.......even I created another project nad copied and pasted the new code into that but I still got the same problem in my new project.....

I dont know whats the reason......I am attaching my complete code here.

Please help.....

Thanks
Nemat
Attachments
RunServiceInBackground.zip
(34.64 KiB) Downloaded 28 times
Nemat
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Thu Aug 21, 2008 3:16 pm
Location: Jaipur

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests