Giriş Aktivty

package com.tutkugurur.realchat;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.inputmethod.InputConnectionCompat;

import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.annotations.NotNull;

public class GirisActivity extends AppCompatActivity {
EditText kullaniciAdiEditText;
Button kayitOlButton;
FirebaseDatabase firebaseDatabase;
DatabaseReference reference;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_giris);
tanimla();
}

public void tanimla()

{ kullaniciAdiEditText = (EditText)findViewById(R.id.kullaniciEditText);
kayitOlButton = (Button)findViewById(R.id.kayitOlButton);
firebaseDatabase = FirebaseDatabase.getInstance();
reference = firebaseDatabase.getReference();

kayitOlButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = kullaniciAdiEditText.getText().toString();
kullaniciAdiEditText.setText("");
ekle(username);
}
public void ekle(final String kadi){
{ reference.child("Kullanıcılar").child(kadi).child("kullanicidiadi").setValue(kadi).addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if(task.isSuccessful()) {
Toast.makeText(getApplicationContext(),"Başarı ile Kayıt Oldunuz", Toast.LENGTH_LONG).show(); }
Intent intent = new Intent(GirisActivity.this,MainActivity.class);
intent.putExtra("kadi",kadi);
startActivity(intent);
}
});
};
}
}
);
}
}




Main Aktivty

package com.tutkugurur.realchat;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

FirebaseDatabase firebaseDatabase;
DatabaseReference reference;
List list;
String userName;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tanimla();
listele();
}
public void tanimla()
{
userName = getIntent().getExtras().getString("kadi");
firebaseDatabase = FirebaseDatabase.getInstance();
reference=firebaseDatabase.getReference();
list = new ArrayList<>();
}

public void listele()
{
reference.child("Kullanıcılar").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
if (!dataSnapshot.getKey().equals("userName"))
list.add(dataSnapshot.getKey());
Log.i("Kullanıcı", dataSnapshot.getKey());
Log.i("Kullanıcı : ", dataSnapshot.getKey());

}

@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

}

@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {

}

@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
}

}