1

我的应用程序中有两种方法,它们想要一个接一个地执行。

removeAllNonSyncedData();
getFullDbFromREST();

第一种方法是removeAllNonSyncedData()从数据库中删除所有非同步数据。

当所有数据都被清除后,我想执行getFullDbFromREST()

private void removeAllNonSyncedData() {
        try {

            ContentResolver cr = getContentResolver();
            ContentProviderHelp helper = new ContentProviderHelp();


            ObjectPropertyValueTable ObjectPropertyValueTable = new ObjectPropertyValueTable(helper);
            ObjectPropertyValueAuditTrailTable ObjectPropertyValueAuditTrailTable = new ObjectPropertyValueAuditTrailTable(helper);
            PhotoInfoTable PhotoInfoTable = new PhotoInfoTable(helper);
            PropertyDefinitionTable PropertyDefinitionTable = new PropertyDefinitionTable(helper);

            SyncManagerTable SyncManagerTable = new SyncManagerTable(helper);


            cr.delete(ObjectPropertyValueTable.getContentURI(), ObjectPropertyValueTable.SyncStatus+"<>1", null);
            cr.delete(ObjectPropertyValueAuditTrailTable.getContentURI(), null, null);
            cr.delete(SyncManagerTable.getContentURI(), null, null);
            cr.delete(PhotoInfoTable.getContentURI(), PhotoInfoTable.SyncStatus+"<>1", null);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

第一种方法完成后如何执行第二种方法(从数据库中完全清除数据)?

4

2 回答 2

3

好吧,这是默认情况,除非您异步调用第一个方法。否则,方法总是一个接一个地执行。

于 2013-07-12T12:06:18.980 回答
0

我已经使用线程实现了这种条件,比如我想在完成写入后写入一个文件,然后我想读取一个文件,所以我让两个线程像以下方式那样读写,并且用户等待和通知功能。

public  Object isWrite=new Object();
    private class WriteThread extends Thread {
        @Override
        public void run() {
            super.run();
            synchronized (isWrite){
                        //Do something as you want
                        isWrite.wait();
        }
}
}

    private class ReadThread extends Thread {
        @Override
        public void run() {
            super.run();
            synchronized (isWrite){
                      //Do something as you want                         
                      isWrite.notify();

        }
}
}

        //Calling of write thread then read thread.
        try {
            WriteThread mWriteThread=new WriteThread();
            mWriteThread.start();

            mReadThread = new ReadThread();
            mReadThread.start();

        } catch (SecurityException e) {
            e.printStackTrace();
        }
于 2013-07-12T12:09:34.237 回答