简体   繁体   中英

Realm File not found ERROR Android

All these time, I was thinking that realm file is created when RealmConfiguration is created. But today when I observed, the realm file is created when the data is written to it using Realm.getDefaultInstance(). We have login / logout function in our App. I have realm configuration defined in Application class.

val realmConfiguration = RealmConfiguration.Builder(this)
                .schemaVersion(1)
                .migration(RealmMigrationClass())
                .build()

Realm.setDefaultConfiguration(realmConfiguration)

During login, I fetch all the details from the user and user related information from backend and store it in realm.

During logout, I delete all the app related data (ie) I delete the files from getFilesDir() as well. So during logout, the realm file gets deleted.

During relogin, Login activity is called (The realmConfiguration in MainApp is undisturbed) and again user details are fetched and saved in realm.

We have social login integrated into app. For Google SignIn, We could not sign out anywhere other than the Login Activity where mGoogleApiClient is initialized. So, during logout we did not logout the google user, we do logout the user during the next signin request.

googleLogin.onClick {

            if(mGoogleApiClient?.isConnected ?:false){
                Auth.GoogleSignInApi.signOut(mGoogleApiClient)
                val signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
                startActivityForResult(signInIntent, RC_GET_TOKEN)
            }else{
                val signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
                startActivityForResult(signInIntent, RC_GET_TOKEN)
            }
        }

We do support our custom login, logout. We do have twitter login / Logout, we do have facebook login/logout in addition to google. But just google sign in alone causes issue during relogin (ie User logs in the app successfully using any mode including google signin. First time works perfectly fine. but if the user signs out and tries relogin with google, it fails. but relogin with other modes custom, facebook and twitter works perfectly fine). After login, while trying to write user details to realm, it complains that the realm file does not exist and shows unexpected error occurred. After that unexpected error, again google sign in starts to work with creating realm properly.

Logout code is as follows.

cacheDir.deleteRecursively()
        filesDir.deleteRecursively()

        AppUtilityFunctions.facebookSignout()
        AppUtilityFunctions.twitterSignout(this)

        //After logging out launch welcome page
        val intent = Intent(this, WelcomeActivity::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
                Intent.FLAG_ACTIVITY_CLEAR_TASK or
                Intent.FLAG_ACTIVITY_TASK_ON_HOME)
        startActivity(intent)


06-13 22:07:29.634 11246-11246/? D/REALM: jni: ThrowingException 5, , .
06-13 22:07:29.634 11246-11246/? D/REALM: Exception has been throw: File not found: .
06-13 22:07:29.634 11246-11246/? D/AndroidRuntime: Shutting down VM
06-13 22:07:29.634 11246-11246/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x9cccdb20)
06-13 22:07:29.634 11246-11272/? E/CrashlyticsCore: Tried to write a fatal exception while no session was open.
06-13 22:07:29.644 11246-11246/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: com.clinicloud.app.dev, PID: 11246
                                                   io.realm.exceptions.RealmIOException: File not found: .
                                                       at io.realm.internal.SharedGroup.createNativeWithImplicitTransactions(Native Method)
                                                       at io.realm.internal.SharedGroup.<init>(SharedGroup.java:67)
                                                       at io.realm.internal.r.<init>(SharedGroupManager.java:47)
                                                       at io.realm.a.<init>(BaseRealm.java:76)
                                                       at io.realm.o.<init>(Realm.java:126)

Anyone has any clue on whats happening?

我通过在Google登录期间删除Auth.GoogleSignInApi.signOut(mGoogleApiClient)来解决此问题,并在我从Google收集了与用户相关的所有信息后放入了退出代码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM