I am trying to use IF with my login stuff. The purpose of this is to create the user in the firebase if it does not exist, and just log in if it does exist. The reason I want to do this, is that I want to put more info under the users UID, but this info gets erased from firebase every time the user logs in, because it always updates the UID and entries below it.
There may be another way to do this, but this is the only solution I was able to find.
The problem I am having is that when building I get an error. See error message below.
This is in my 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) {
}
});
}
Error when building
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
How can I correct this issue?
Thanks Rune
replace
Intent intent = new Intent(this, HomeActivity.class);
with
Intent intent = new Intent(MainActivity.this, HomeActivity.class);