반응형
package com.example.diet_memo
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.widget.Toast
import com.google.firebase.Firebase
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.auth
import java.lang.Exception
class SplashActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
auth = Firebase.auth
//처음 접속할 때 비회원으로 로그인이 기존에 되어있으면 메세지가 뜨고 메인 액티비티로 넘겨줌
try{
Log.d("SPLASH", auth.currentUser!!.uid)
Toast.makeText(this, "원래 비회원 로그인이 되어있는 사람입니다", Toast.LENGTH_LONG).show()
Handler().postDelayed({
startActivity(Intent(this, MainActivity::class.java))
finish() },3000)
//기존에 비회원으로 로그인이 안되어있으면 회원가입 시켜줘야 한다고 뜨는것
} catch (e : Exception) {
Log.d("SPLASH", "회원가입 시켜줘야함")
auth.signInAnonymously()
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Toast.makeText(this, "비회원 로그인 성공", Toast.LENGTH_LONG).show()
Handler().postDelayed({
startActivity(Intent(this, MainActivity::class.java))
finish() },3000)
} else {
// If sign in fails, display a message to the user.
Toast.makeText(this, "비회원 로그인 실패", Toast.LENGTH_LONG).show()
}
}
}
}
}
반응형
'kotlin↗ > 안드로이드 스튜디오 메이킹' 카테고리의 다른 글
[KOTLIN] Dialog에 날짜 선택 만드는 코드 (0) | 2024.02.07 |
---|---|
[KOTLIN] 다이얼로그 Dialog 생성 (0) | 2024.02.07 |
[KOTLIN] FIREBASE 파이어베이스 익명 로그인 (1) | 2024.02.06 |
KOTLIN]해당 이미지(버튼)을 누르면 원하는 화면으로 넘어가기 (0) | 2024.02.01 |
KOTLIN]이미지 일정하게 간격 두면서 테두리 둥글게 만들기 (0) | 2024.02.01 |