How to Read AsyncStorage on Android Correctly

前端 未结 2 1150
死守一世寂寞
死守一世寂寞 2020-12-06 23:17

It seems that it\'s possible access the AsyncStorage from Android (native); but I still struggling to make this work.

In my React Native application, I

2条回答
  •  自闭症患者
    2020-12-06 23:33

    I had a problem with alarm clock in my application and I decided to use AsyncStorage on Android side, then I use the code below and I could get all values from AsyncStorage and generate all alarms that was registered in my application's AsyncStorage.

    SQLiteDatabase readableDatabase = null;
            readableDatabase = ReactDatabaseSupplier.getInstance(this.reactContext).getReadableDatabase();
            Cursor catalystLocalStorage = readableDatabase.query("catalystLocalStorage", null, null, null, null, null, null);
            try {
                List listaAlarmes = new ArrayList<>();
                if (catalystLocalStorage.moveToFirst()) {
    
                    do {
                        //Ex: key: 01082019_0800
                        //value: [{executionDate: 2019-08-01T08:00}]
                        String key = catalystLocalStorage.getString(0);
                        String json = catalystLocalStorage.getString(1);
    
                        if (dados.length == 3) {
                            ...generate my alarms with key and json
                        }
    
                    } while (catalystLocalStorage.moveToNext());
    
                }//2_31082019_0900 - [{"idPrescricaoMedicamento":35,"nomeMedicamento":"VITAMINA"}]
    
            } finally {
                if (catalystLocalStorage != null) {
                    catalystLocalStorage.close();
                }
    
                if (readableDatabase != null) {
                    readableDatabase.close();
                }
            }
    

提交回复
热议问题