使用parse.com lib创建应用程序。当我关闭应用程序重新打开它时,它说不幸停止了

时间:2015-07-28 03:15:43

标签: android parse-platform

我已经创建了诸如启动画面,登录页面,注册页面和主页等活动,但当我关闭我的应用并尝试重新打开时,它显示错误,不幸停止

以下是我的启动画面活动代码:

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import com.parse.Parse;
import com.parse.ParseUser;

public class Splash extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        Parse.enableLocalDatastore(this);

        Parse.initialize(this, "app. id.(i can't show this privacy purpose :))",
            "Clint key(same here for privecy i will not show) ");

        Thread timer=new Thread(){
            public void run(){
                try{
                    sleep(5000);
                }catch (Exception e){
                    e.printStackTrace();

                }finally {
                    ParseUser currentUser = ParseUser.getCurrentUser();
                    if (currentUser != null) {
                        // do stuff with the user
                        Intent taketohome=new Intent(Splash.this,HomepageActivity.class);
                        startActivity(taketohome);
                    } else {
                        // show the signup or login screen
                        Intent taketologinpage=new Intent(Splash.this, LoginActivity.class);
                        startActivity(taketologinpage);
                    }
                }
            }

        };timer.start();
    }

    @Override
    protected void onPause() {
        super.onPause();
        finish();
    }
}

1 个答案:

答案 0 :(得分:1)

实际上这种情况正在发生,因为您正在onCreate活动方法中进行Parse.intailize。相反,你可以创建一个应用程序类并在那里初始化Parse。希望它能解释清楚

Caused by: java.lang.IllegalStateException: ParsePlugins is already initialized