Android Db locked
<p>Using Sqlite db, I am populating my list. That List is refreshed every minute(using Timer). Also I am updating/inserting Sqlite db(using Service), checking for new data. </p>

<p>This is also happening every minute. This is working but sometimes "Database is getting locked". How can I manage this and not get that error.  Appreciate your input.</p>

<pre><code>public class Services extends Service {

Context context;
int NOTIFICATION_ID = 1;
NotificationManager notificationManager, chatNotificationManager;
boolean connected = false;
boolean notconnected = false;
int numChat = 0;
int numTask = 0;
List&lt;String&gt; list =  new ArrayList();
String android_id, syncDecision;

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

@Override 
public void onCreate() {
    super.onCreate();
} 

@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
    android_id = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);

    context = getBaseContext();

    /*
     * THIS TIMER CONTAINS ANY SERVICE THAT ACCESSES THE SQLite database
     */
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            Log.d(TAG, "starting to do work in timer1");
            synchronizeSQLiteDatabases();
        }
    }, 0, 60000);


private void synchronizeSQLiteDatabases() {
    try {

        if (Functions.isOnline(context) )
        {
        // ---------------------------------- COMMENT UPLOAD ----------------------------
        if (!((GlobalMobileVianet) this.getApplication()).getUserid().equals("000000")) {
             try
             {
                Log.i(TAG, "uploading comment data");
                DataUploader_Comment commentupdater = new DataUploader_Comment(((GlobalMobileVianet) this.getApplication()).getUserid(), 
                        ((GlobalMobileVianet) this.getApplication()).getPassword(), context);
                commentupdater.run();
             }
             catch(Exception e)
             {
                    Log.i(TAG, "    CATCH uploading comment data" + e.toString());

             }
        }
        else
        {
            //Functions.logout(getApplicationContext());
            Log.i(TAG, "    NOT uploading comment data");
        }
        //--------------------------------------- TASK UPLOAD --------------------------------
        if ( !((GlobalMobileVianet) this.getApplication()).getUserid().equals("000000")) {

                try{
                    Log.i(TAG, "uploading task data");
                    DataUploader_Task taskuploader = new DataUploader_Task(((GlobalMobileVianet) this.getApplication()).getUserid(), 
                        ((GlobalMobileVianet) this.getApplication()).getPassword(), context);
                    taskuploader.run();
                }
                catch(Exception e)
                {
                    Log.i(TAG, "    CATCH uploading task data" + e);

                }
        }
        else
        {
            //Functions.logout(getApplicationContext());
            Log.i(TAG, "    NOT uploading task data");
        }

        // ------------------------------------------AC DOWNLOAD ---------------------------------
        if (!((GlobalMobileVianet) this.getApplication()).getUserid().equals("000000")) {


                try{
                    Log.i(TAG, "running aircraft data download");
                    DataLoader_Aircraft acloader = new DataLoader_Aircraft(((GlobalMobileVianet) this.getApplication()).getUserid(), 
                        ((GlobalMobileVianet) this.getApplication()).getPassword(), context, "N");
                    acloader.run();
                }
                catch(Exception e)
                {
                    Log.i(TAG, "    CATCH running aircraft data download" + e.toString());

                }
        }
        else
        {
            //Functions.logout(getApplicationContext());
            Log.i(TAG, "    NOT running aircraft data download");
        }

        // ------------------------------------ TASK DOWNLOAD ------------------------------------
        if (  !((GlobalMobileVianet) this.getApplication()).getUserid().equals("000000")) {

            try{
                Log.i(TAG, "running task data download");
                DataLoader_Task tasksloader = new DataLoader_Task(((GlobalMobileVianet) this.getApplication()).getUserid(), 
                        ((GlobalMobileVianet) this.getApplication()).getPassword(), context, "N");
                tasksloader.run();
            }
            catch(Exception e)
            {
                Log.i(TAG, " CATCH running task data download" + e.toString());

            }
        }
        else
        {
            //Functions.logout(getApplicationContext());
            Log.i(TAG, "    NOT running task data download");
        }

        // -------------------------------- EMPLOYEE DOWNLOAD -----------------------------------
        if (!((GlobalMobileVianet) this.getApplication()).getUserid().equals("000000")) {

            try
            {
                Log.i(TAG, "running employee data download");
                DataLoader_Employee employeeloader = new DataLoader_Employee(((GlobalMobileVianet) this.getApplication()).getUserid(), 
                        ((GlobalMobileVianet) this.getApplication()).getPassword(), context, "N");
                employeeloader.run();
            }
            catch(Exception e)
            {
                Log.i(TAG, "    CATCH running employee data download " + e.toString());

            }
        }
        else
        {
            //Functions.logout(getApplicationContext());
            Log.i(TAG, "    NOT running employee data download");
        }

        // ------------------------------------COMMENT DOWNLOAD -----------------------------------------
        if (!((GlobalMobileVianet) this.getApplication()).getUserid().equals("000000")) {

            try{
                Log.i(TAG, "running comment data update");
                DataLoader_Comment commentloader = new DataLoader_Comment(((GlobalMobileVianet) this.getApplication()).getUserid(), 
                        ((GlobalMobileVianet) this.getApplication()).getPassword(), context, "N");
                commentloader.run();
            }
            catch(Exception e)
            {
                Log.i(TAG, "    CATCH running comment data update" + e.toString());

            }
        }
        else
        {
            //Functions.logout(getApplicationContext());
            Log.i(TAG, "    NOT running comment data download");
        }

        } 
    } catch (Exception e) {
        Log.e(TAG,
                "synchronizeSQLiteDatabases exception: " + e.toString());
    }

}
</code></pre>

<p>and this is activity which refreshes the list</p>

<pre><code>public class TestExList extends ExpandableListActivity{

 String empid, ctext, fleet_name, rString;
 private DbAdapter_Assignment assignment;
 private DbAdapter_Task task;
 private DbAdapter_Comment comment;
 private DbAdapter_Aircraft aircraft;
 private Cursor accursor, taskcursor;
 private ExpandableListView expListView;
 private Timer taskTimer;
 private ListView lv;
 private Camera cam;
 private boolean onoff;

 private boolean testValue;

 private SimpleCursorTreeAdapter cursorTreeAdapter;

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        empid = getIntent().getExtras().getString("EmpID");
        Log.d("testValue","from onCreate, onoff is " + onoff);

        setHeader();

        if(empid.equals(Functions.getLoginEmpID(this))){
            getData(empid);
        }
        taskTimer = new Timer();
        taskTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                TimerMethod();
            }

        }, 0, 60000);
        expListView.invalidateViews();
    } 


    private void TimerMethod()
    {
        this.runOnUiThread(Timer_Tick);
    }

    private Runnable Timer_Tick = new Runnable() {
        public void run() {
                if(Functions.getServiceStatus(getBaseContext()) != "No service")
                {
                    if(empid.equals(Functions.getLoginEmpID(getBaseContext())))
                    {
                        getData(empid);
                    }
                }
        }
    };
    @Override 
    public void onDestroy()
    {
        super.onDestroy();
        try
        {
            accursor.close();
            taskcursor.close();
            task.close();
            comment.close();
            aircraft.close();
            assignment.close();
        }
        catch(Exception e)
        {
            Log.e("ViaNetError", "Unable to close cursors.");
        }

        if(cam != null)
        {
            cam.release();
            cam = null;
        }
    }


    public void getData(final String empid)
    {
         Log.e("Testing", "Getting data for emp: " + empid);
        assignment =  new DbAdapter_Assignment(getBaseContext());
         assignment.open();
         task =  new DbAdapter_Task (getBaseContext());
         task.open();
         comment = new DbAdapter_Comment (getBaseContext());
         comment.open();

    }
    }
</code></pre>
