Android从Parse切换到Parse Server崩溃 [英] Android switch from Parse to Parse Server crashes

查看:100
本文介绍了Android从Parse切换到Parse Server崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Android和iOS应用程序从Parse.com迁移到Parse Server.首先,我正在使用测试应用程序进行此迁移,以确保一切正常. 使用iOS没问题,但是使用Android,每次用户输入应用程序时更新的应用程序就会崩溃.

这是更新的Android代码:

public static void initParse(Application app) {
    ctxt = app.getApplicationContext();
    Parse.enableLocalDatastore(app);
    // Old version
    //Parse.initialize(app, "<my app id>", "<my client key>");
    // New version
    Parse.initialize(new Parse.Configuration.Builder(ctxt)
            .applicationId("<my app id>")
            .clientKey(null)
            .server("https://<my new server>/parse/")
            .build()
    );
    ParseUser.enableRevocableSessionInBackground();
}

崩溃返回"com.parse.ParseException:java.lang.IllegalStateException:无法编码与未保存的ParseObject的关联",并考虑到我在Stackoverflow中阅读的内容,这是因为ParseUser.getCurrentUser( )返回null(尽管用户已登录)并且Parse方法失败.

实际上,如果我使用相同的代码,则取消注释旧版本的Parse.initialize,注释新版本的Parse.initialize,编译并启动该应用程序,这将毫无问题地启动,用户可以正确使用它.

但是再次,如果我评论旧版本的Parse.initialize,取消注释新版本的Parse.initialize,编译并启动该应用程序,则这将立即崩溃,因为ParseUser.getCurrentUser()返回null且Parse方法失败. >

我在这里想念什么?我应该强迫我的用户再次登录吗?在我看来,这是一个糟糕的UX,无论如何,在iOS中,我对新版本没有任何疑问,两个平台之间有什么区别?

根据Robert Rowntree的建议,我已将初始化更改为:

public static void initParse(Application app) {
    ctxt = app.getApplicationContext();
    Parse.enableLocalDatastore(app);
    // Old version
    //Parse.initialize(app, "<my app id>", "<my client key>");
    // New version
    Parse.initialize(new Parse.Configuration.Builder(ctxt)
            .applicationId("<my app id>")
            .clientKey("<my client key>")
            .server("https://<my new server>/parse/")
            .build()
    );
    //Parse.setLogLevel(Parse.LOG_LEVEL_DEBUG);
    Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
    ParseUser.enableRevocableSessionInBackground();
}

除此之外,我还检查了我的Parse版本是否为最新版本,并将其保存在gradle文件中:

compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'

结果是一样的,我第一次对Parse调用时,应用程序崩溃,并出现"com.parse.ParseException:java.lang.IllegalStateException:无法编码与未保存的ParseObject的关联". 除此之外,我看到的与解析相关的唯一日志是与GCM令牌相关的日志,

我尝试了另一件事,使用旧的初始化方法卸载应用程序,并使用新的初始化方法安装它,并且我猜新版本现在可以正常工作了.

但是,当然,这不是我的解决方案,我无法告诉用户卸载应用并再次安装.

但这是一个提示:使用新的Parse Server打开应用程序时,新的初始化没有问题,但是旧的Parse如何反应",getCurrentUser或类似内容中肯定有任何不一致之处.

解决方案

可以尝试这样初始化吗:

Parse.initialize(new Parse.Configuration.Builder(this)
                        .applicationId("APP_ID")
                        .clientKey("CLIENT_KEY")
                        .server("https://SERVER_URL/parse/") // The trailing slash is important.
                        .enableLocalDataStore()
                        .build()
                );

注意

.enableLocalDataStore()

在初始化中.删除此内容:

Parse.enableLocalDatastore(app);

I'm migrating my Android and iOS app from Parse.com to Parse Server. First I'm doing this migration with a test app to be sure everything is ok. With iOS there has been no problem but with Android the updated app crashes each time the user enters in the app.

This is the Android code updated:

public static void initParse(Application app) {
    ctxt = app.getApplicationContext();
    Parse.enableLocalDatastore(app);
    // Old version
    //Parse.initialize(app, "<my app id>", "<my client key>");
    // New version
    Parse.initialize(new Parse.Configuration.Builder(ctxt)
            .applicationId("<my app id>")
            .clientKey(null)
            .server("https://<my new server>/parse/")
            .build()
    );
    ParseUser.enableRevocableSessionInBackground();
}

The crash returns a "com.parse.ParseException: java.lang.IllegalStateException: unable to encode an association with an unsaved ParseObject", and taking into account what I've read in Stackoverflow, this is because ParseUser.getCurrentUser() returns null (despite the user is logged in) and Parse methods fail.

In fact, if I take this same code, uncomment the old version of Parse.initialize, comment the new version of Parse.initialize, compile and launch the app, this is launched without problems and the user can use it properly.

But again, if I comment the old version of Parse.initialize, uncomment the new version of Parse.initialize, compile and launch the app, this crashes inmediately because ParseUser.getCurrentUser() returns null and Parse methods fail.

What am I missing here? Should I force my users to login again? This seems to me a bad UX, and anyway, in iOS I have no problems with the new version, what is the difference between both platforms?

EDIT 1:

Following Robert Rowntree advice I've changed the initialization to this:

public static void initParse(Application app) {
    ctxt = app.getApplicationContext();
    Parse.enableLocalDatastore(app);
    // Old version
    //Parse.initialize(app, "<my app id>", "<my client key>");
    // New version
    Parse.initialize(new Parse.Configuration.Builder(ctxt)
            .applicationId("<my app id>")
            .clientKey("<my client key>")
            .server("https://<my new server>/parse/")
            .build()
    );
    //Parse.setLogLevel(Parse.LOG_LEVEL_DEBUG);
    Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
    ParseUser.enableRevocableSessionInBackground();
}

Besides this I've checked that my Parse version is the last available, I have this in my gradle file:

compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'

And the result is the same, the app crashes with "com.parse.ParseException: java.lang.IllegalStateException: unable to encode an association with an unsaved ParseObject" the first call I make to Parse. Besides this, the unique log I can see related to parse is one related to GCM token, nothing else.

EDIT 2:

I've tried another thing, uninstall the app with the old initialization and install it with the new initialization and as I guessed the new version is now working.

But, of course this is not a solution to me, I can not tell my users to uninstall the app ans install it again.

But this is a hint: there is no problem with the new initialization but with how the old Parse "reacts" when opening the app with the new Parse Server, there must be any inconsistency in getCurrentUser or something like that.

解决方案

Can you try initializing like this:

Parse.initialize(new Parse.Configuration.Builder(this)
                        .applicationId("APP_ID")
                        .clientKey("CLIENT_KEY")
                        .server("https://SERVER_URL/parse/") // The trailing slash is important.
                        .enableLocalDataStore()
                        .build()
                );

notice the

.enableLocalDataStore()

is in the initilization. Remove this:

Parse.enableLocalDatastore(app);

这篇关于Android从Parse切换到Parse Server崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆