데이터베이스 생성하기
데이터 베이스 연결하기
https://firebase.google.com/docs/database/android/start?hl=ko
Firebase에 앱 연결 | Firebase Realtime Database
Join us in person and online for Firebase Summit on October 18, 2022. Learn how Firebase can help you accelerate app development, release your app with confidence, and scale with ease. Register now 의견 보내기 Firebase에 앱 연결 컬렉션을 사
firebase.google.com
implementation 'com.google.firebase:firebase-database-ktx'
- 위에 코드를 buid.gradle(Module)에 넣고 Sync Now하기
activity_main.xml에 저장하기 버튼을 만듬
<Button
android:id="@+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="저장하기"/>
MainActivity.kt에 저장하기 버튼을 누르면 파이어베이스에 저장하도록 함
// 저장하기 기능
val saveBtn = findViewById<Button>(R.id.saveBtn)
saveBtn.setOnClickListener {
// Write a message to the database
val database = Firebase.database
val myRef = database.getReference("message")
// myRef.setValue("저장하기")
myRef.push().setValue("저장하기") // push()를 입력하면 계속 저장이 가능해짐
}
'Android > 기능' 카테고리의 다른 글
[Android] 파이어베이스 회원가입, 로그인, 익명 로그인 (0) | 2022.10.11 |
---|---|
[Android]안드로이드 스튜디오에 파이어베이스(Firebase) 연동하기 (0) | 2022.10.11 |