앱2 코틀린 Object와 Companion Object 차이? - kotlin 오늘은 비슷한거 같으면서 다른 Object declaration와 Companion object의 차이에 대해서 알아보려한다. 보통 Kotlin에서 Java의 static과 같은 정적 변수 및 메서드를 사용하기 위해 보통 object나 Companion object를 사용하는데 object부터 차근차근 알아보자. Object declaration이란? Object declaration은 싱글톤 패턴을 더 쉽게 사용하기 위해 코틀린에서 제공하는 일종의 객체 선언 키워드라고 볼 수 있다. 예시 코드를 한번 봐보자. object ObjectDecl { const val OB_STRING = "1" fun obtest() {} } Object는 위와 같은 형태로 선언할 수 있고 다음과 같은 특징이 있다. Sin.. 2023. 4. 28. 안드로이드 Fragment에서 현재 위치(위도, 경도) 가져오는 방법 오늘은 Fragment에서 현재 위치(위도, 경도)를 가져오는 방법에 대해서 알아볼 것이다. 코드를 통해 차근차근 알아보자 GpsTracker.java 먼저 GpsTraker 코드부터 보겠다. package com.example.pethealth; import android.Manifest; import android.app.Service; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationListener; import android.location.L.. 2023. 4. 23. 이전 1 다음