Skip to content

[Android]: Database locale issues #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.GuardedAsyncTask;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
Expand All @@ -33,7 +34,7 @@

@ReactModule(name = AsyncStorageModule.NAME)
public final class AsyncStorageModule
extends ReactContextBaseJavaModule implements ModuleDataCleaner.Cleanable {
extends ReactContextBaseJavaModule implements ModuleDataCleaner.Cleanable, LifecycleEventListener {

// changed name to not conflict with AsyncStorage from RN repo
public static final String NAME = "RNC_AsyncSQLiteDBStorage";
Expand Down Expand Up @@ -91,6 +92,7 @@ public AsyncStorageModule(ReactApplicationContext reactContext) {
AsyncStorageModule(ReactApplicationContext reactContext, Executor executor) {
super(reactContext);
this.executor = new SerialExecutor(executor);
reactContext.addLifecycleEventListener(this);
mReactDatabaseSupplier = ReactDatabaseSupplier.getInstance(reactContext);
}

Expand Down Expand Up @@ -118,6 +120,18 @@ public void clearSensitiveData() {
mReactDatabaseSupplier.clearAndCloseDatabase();
}

@Override
public void onHostResume() {}

@Override
public void onHostPause() {}

@Override
public void onHostDestroy() {
// ensure we close database when activity is destroyed
mReactDatabaseSupplier.closeDatabase();
}

/**
* Given an array of keys, this returns a map of (key, value) pairs for the keys found, and
* (key, null) for the keys that haven't been found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@

package com.reactnativecommunity.asyncstorage;

import javax.annotation.Nullable;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;

import com.facebook.common.logging.FLog;
import com.facebook.react.common.ReactConstants;
import javax.annotation.Nullable;

/**
* Database supplier of the database used by react native. This creates, opens and deletes the
Expand Down Expand Up @@ -151,7 +149,7 @@ private synchronized boolean deleteDatabase() {
return mContext.deleteDatabase(DATABASE_NAME);
}

private synchronized void closeDatabase() {
public synchronized void closeDatabase() {
if (mDb != null && mDb.isOpen()) {
mDb.close();
mDb = null;
Expand Down