安卓firebase用户登录问题,意图在if语句中



我正在尝试将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

如何更正此问题?

谢谢符文

替换

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

带有

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

相关内容

  • 没有找到相关文章

最新更新