即使我没有注销,Parse用户也会注销

时间:2015-08-05 22:25:01

标签: android parse-platform

所以,这是我启动应用程序时的Launcher活动,我检查是否有人登录,但ParseUser.getCurrentUser()总是返回null我认为。当我登录然后关闭应用程序而不注销并再次启动它时,getCurrentUser()再次返回null,但它不应该。 logIn函数位于另一个名为HumLogModel的类中,我在此下面编写。

public class LauncherActivity extends ActionBarActivity {

    private Intent logInActivityIntent;
    private Intent homeActivityIntent;
    private HumLogController humLogController;
    private HumLogModel humLogModel;
    private String username;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launcher);
        initializeParse();
        username = getCurrentUser();

        if (username.equalsIgnoreCase("null")) {
            humLogModel = new HumLogModel();
            humLogController = new HumLogController();
            startLogInActivity();
        }
        else {
            humLogModel = new HumLogModel();
            humLogController = new HumLogController();
            startHomeActivity();
        }
    }


 private String getCurrentUser(){
        ParseUser currentUser = ParseUser.getCurrentUser();
        if (currentUser != null) {
            return currentUser.getUsername();
        } else {
            return "null";
        }
    }
}

这是我们启动解析数据存储的地方。     private void initializeParse(){         Parse.enableLocalDatastore(本);         Parse.initialize(this," LrAF8blaE0GR19ffsr78rHKEH50QBcnZFDSuj9BW"," 2UBZlOgM78UNj7AcxcArmuOlxy5y3UstpJP1h9lb");     }

 This is the Model class which have the logIn method which are called up when some one log's in and also the logOut method (but even logOut method is never called , user is logged out I think .!!!) 

public class HumLogModel extends Application implements Serializable {

    private  transient ParseObject customer;
    private  transient ParseObject tradesman;
    private  transient ParseObject user;

    public HumLogModel(){
        customer = new ParseObject("Customer");
        tradesman = new ParseObject("Tradesman");
        user = new ParseObject("User");
    }

    public void createNewUser(String username, String password , String userType){
        user.put("username" , username);
        user.put("password", password);
        user.put("userType", userType);
        user.saveInBackground();

        ParseUser newUser = new ParseUser();
        newUser.setUsername(username);
        newUser.setPassword(password);
        newUser.signUpInBackground(new SignUpCallback() {
            public void done(ParseException e) {
                if (e == null) {
                    // Hooray! Let them use the app now.
                } else {
                    // Sign up didn't succeed. Look at the ParseException
                    // to figure out what went wrong
                }
            }
        });
    }

    public void logIn(String username , String password){
        ParseUser.logInInBackground(username, password, new LogInCallback() {
            public void done(ParseUser user, ParseException e) {
                if (user != null) {
                    // Hooray! The user is logged in.
                } else {
                    // Signup failed. Look at the ParseException to see what happened.
                }
            }
        });
    }

    public void logOut(){
        ParseUser.logOut();
    }

}

当我关闭应用程序并再次启动时,它始终以LogInactivity开始,但如果不登录则不应该

0 个答案:

没有答案