how to reschedule timer in android for wallpaper service
<p>I have use the following code. first time it work properly but..when i try to do it 2nd time it doesn't give ant output.whenever I change the duration it should display the image in background for the particular time.![the duration is change according to image][1]
my code for wallpaper service is as follow:</p>

<pre><code>package com.my.wallpaper;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;

public class WallpaperChangeService extends Service {

private Timer timer;
private long duration; 
SharedPreferences.Editor editor;
private Helper obj;
private String TAG = "WallpaperChangeService";
//private int count = 0;
private int cursor_count = 0;
Context ctx;
Bitmap thumb = null;
@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}
@Override
public void onStart(Intent intent, int startId) {
    // TODO Auto-generated method stub
    super.onStart(intent, startId);
     Log.d("TIMER..........","");
    try

    {

        SharedPreferences pref =(SharedPreferences) PreferenceManager.getDefaultSharedPreferences(this);

        String dur =pref.getString("status", "");

        String[] element = dur.split(" ");

        String strdur =element[0];

        Long l = Long.parseLong(strdur);

        duration = (Long)(l * 60);
        Log.d("WallStatus..........", dur);
        Log.d("StatusDur..........", strdur);
        Log.d("Convert Into L=.........", ""+l);
        Log.d("Duration=.........", ""+duration);
        timer = new Timer("WallpaperTimer");
        timer.schedule(updateTask, 20000L, duration*1000L);
        Log.d("TIMER..........","");
    }catch (Exception e) {
        e.printStackTrace();
    }
}

private TimerTask updateTask = new TimerTask() {
    @Override
    public void run() {
        try
        {
            obj = new Helper(WallpaperChangeService.this);
            cursor_count = obj.giveCursorCount();
            if(cursor_count&gt;0)
            {

                Log.d("Service Duration=.........", ""+duration);
            Log.d("Service Timer ", "Wallpaper changed..");
            Log.d("Service Timer ", "Position : " + Global.position);
            Log.d("Service Timer ", "Path : " + obj.getRealPathFromURI(Global.position));
            //Uri contentURI = obj.giveUriFromPosition(Global.position);

                //thumb = BitmapFactory.decodeStream(getContentResolver().openInputStream(contentURI));
                thumb = BitmapFactory.decodeFile(obj.getRealPathFromURI(Global.position));

            //set wallpaper
            obj.callSetWallpaperMethod(thumb);


            Global.position = Global.position + 1;
            if(Global.position == cursor_count)
            {
                Global.position = 0;
            }
                        }
            else
            {
                Log.e("Timer ", "No image found in gallery..");
            }
            Log.e("Timer ", "............");
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            Log.e(TAG, "Error in update Timer Task..");
            Log.e("Error...", ex.getMessage());
        }
    }
};
  }
</code></pre>
