0

我正在尝试将 IF 与我的登录内容一起使用。这样做的目的是如果用户不存在就在firebase中创建用户,如果用户存在就登录。我想这样做的原因是我想在用户 UID 下放置更多信息,但是每次用户登录时,这些信息都会从 firebase 中删除,因为它总是更新 UID 和它下面的条目。

可能有另一种方法可以做到这一点,但这是我能找到的唯一解决方案。

我遇到的问题是在构建时出现错误。请参阅下面的错误消息。

这是在我的 MainActivity.java

@Override
public void onFirebaseLoggedIn(final AuthData authData) {
    // TODO: Handle successful login
    Firebase userRef= new Firebase("https://theatre-assistant.firebaseio.com/users");
    userRef.child(authData.getUid()).addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            if (snapshot.getValue() != null) {
                Intent intent = new Intent(this, HomeActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);

            } else {
                final Firebase ref = new Firebase("https://theatre-assistant.firebaseio.com/");
                // Authentication just completed successfully :)
                Map<String, String> map = new HashMap<>();
                map.put("provider", authData.getProvider());
                if (authData.getProviderData().containsKey("displayName")) {
                    map.put("displayName", authData.getProviderData().get("displayName").toString());
                    map.put("profileImageURL", authData.getProviderData().get("profileImageURL").toString());

                }
                ref.child("users").child(authData.getUid()).setValue(map);
                Intent intent = new Intent(this, HomeActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);

            }
        }

        @Override
        public void onCancelled(FirebaseError arg0) {
        }
    });

}

构建时出错

Users/runelangaard/AndroidStudioProjects/TheatreAssistant/app/src/main/java/com/langaard/theatreassistant/MainActivity.java:61: error: no suitable constructor found for Intent(<anonymous ValueEventListener>,Class<HomeActivity>)
                    Intent intent = new Intent(this, HomeActivity.class);
                                    ^
    constructor Intent.Intent(String,Uri,Context,Class<?>) is not applicable
      (actual and formal argument lists differ in length)
    constructor Intent.Intent(Context,Class<?>) is not applicable
      (actual argument <anonymous ValueEventListener> cannot be converted to Context by method invocation conversion)
    constructor Intent.Intent(String,Uri) is not applicable
      (actual argument <anonymous ValueEventListener> cannot be converted to String by method invocation conversion)
    constructor Intent.Intent(String) is not applicable
      (actual and formal argument lists differ in length)
    constructor Intent.Intent(Intent) is not applicable
      (actual and formal argument lists differ in length)
    constructor Intent.Intent() is not applicable
      (actual and formal argument lists differ in length)
/Users/runelangaard/AndroidStudioProjects/TheatreAssistant/app/src/main/java/com/langaard/theatreassistant/MainActivity.java:77: error: no suitable constructor found for Intent(<anonymous ValueEventListener>,Class<HomeActivity>)
                    Intent intent = new Intent(this, HomeActivity.class);
                                    ^
    constructor Intent.Intent(String,Uri,Context,Class<?>) is not applicable
      (actual and formal argument lists differ in length)
    constructor Intent.Intent(Context,Class<?>) is not applicable
      (actual argument <anonymous ValueEventListener> cannot be converted to Context by method invocation conversion)
    constructor Intent.Intent(String,Uri) is not applicable
      (actual argument <anonymous ValueEventListener> cannot be converted to String by method invocation conversion)
    constructor Intent.Intent(String) is not applicable
      (actual and formal argument lists differ in length)
    constructor Intent.Intent(Intent) is not applicable
      (actual and formal argument lists differ in length)
    constructor Intent.Intent() is not applicable
      (actual and formal argument lists differ in length)
2 errors

 FAILED

我该如何纠正这个问题?

谢谢符文

4

1 回答 1

2

代替

Intent intent = new Intent(this, HomeActivity.class);

Intent intent = new Intent(MainActivity.this, HomeActivity.class);
于 2016-04-01T12:51:46.767 回答