如果声明

时间:2016-04-01 12:42:54

标签: android firebase firebaseui

我正在尝试使用我登录的内容。 这样做的目的是在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

如何更正此问题?

由于 符文

1 个答案:

答案 0 :(得分:2)

替换

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

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