[英]Parse database initialization- app crashes when navigating back to MainActivity
When my project starts up it's fine.当我的项目启动时,它很好。 MainActivity starts and then it navigates to another page but when I navigate back to MainActivity I sometimes get this error. MainActivity 启动,然后导航到另一个页面,但是当我导航回 MainActivity 时,有时会出现此错误。 http://imgur.com/FVhWMHn I'm positive this is from calling Parse.enableLocalDatastore
before Parse.initialize
but here is my code for mainActivity http://imgur.com/FVhWMHn我肯定这是在Parse.enableLocalDatastore
之前调用Parse.initialize
但这是我的 mainActivity 代码
Parse.enableLocalDatastore(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Parse.initialize(this, "MY_INFO", "MY_INFO_AGAIN");
// check if a user is not cached
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser == null)
{
// prompt user to LoginOrSignUp screen
Intent intent = new Intent(MainActivity.this, LoginOrSignUpActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}`
local data store is called before initialize but it still crashes.在初始化之前调用本地数据存储,但它仍然崩溃。 I don't get it.我不明白。 I can communicate with my data base just fine and everything but as soon as I navigate back to main it crashes我可以很好地与我的数据库通信,一切都很好,但是一旦我导航回主程序,它就会崩溃
you should initialize your Parse SDK in separate class as follows您应该在单独的类中初始化您的 Parse SDK,如下所示
public class SampleApplication extends Application {
public void onCreate(){
super.onCreate();
Parse.enableLocalDatastore(getApplicationContext());
Parse.initialize(this, "PARSE_APP_KEY", "PARSE_CLIENT_KEY");
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
IMPORTANT!!!重要的!!! you need to put this class info in your AndroidManifest.xml file.你需要把这个类信息放在你的 AndroidManifest.xml 文件中。 hope it helps!希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.