简体   繁体   English

解析数据库初始化 - 导航回 MainActivity 时应用程序崩溃

[英]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.

相关问题 从启动画面切换到MainActivity时,应用程序崩溃 - App Crashes When Switching from Splash Screen to MainActivity 单击android中的后退按钮时应用程序崩溃 - App Crashes when click back button in android 如果由于解析异常而被后退按钮破坏,则Android应用程序崩溃 - Android app crashes if destroyed by back button because of Parse exception 应用程序崩溃在onCreate中完成某些操作(这不是声明或初始化)但在onClick中没有 - App Crashes When Something done in onCreate (That is not declarations or initialization)but not in onClick 按下后退按钮时,Android应用程序崩溃 - Android app crashes when back button is pressed 全屏通过MainActivity崩溃应用程序 - Going Fullscreen Through MainActivity Crashes the App 应用程序启动时崩溃,向mainActivity添加按钮代码 - App crashes on launch adding button code to mainActivity 当我在其他Activity中使用MainActivity中的方法时,Android应用程序崩溃 - My Android app crashes when I use method from MainActivity in an other Activity 当应用未运行时,应用在解析推送通知时崩溃 - App crashes on parse push notification when the app is not running 在Android中向“第二个活动”添加了一个“返回至第一个”按钮。 现在,导航到第二个活动时应用程序崩溃 - Added A Button To Second Activity In Android To Return To First. Now App Crashes When Navigating To Second Activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM