1. 변수 선언

var : 초기화 이후 수정 가능

val : 초기화 이후 수정 불가능

? : nullable

 

2. 배열 선언

var intlist = ArrayList<Int>();

 

3. 함수 선언

fun myfunc(str:String){

}
fun myfunc(str:String):String{
    return str
}

 

4. 조건문

if(){
    // true
}else{
    // false
}

 

5. 반복문

for (i in 0..1){
    
}

 

6. lateinit : 선언만하고 나중에 초기화

 

7. lazy : 변수를 사용할때 초기화

 

1. 권한 설정

<uses-permission android:name="android.permission.INTERNET"/>
<application        
        android:usesCleartextTraffic="true">


2. build.gradle(app)

dependencies {
implementation 'com.android.volley:volley:1.2.1'
}


3. 싱글톤 클래스 생성(RequestQueue 설정)

class MySingleton constructor(context: Context) {
    companion object {
        @Volatile
        private var INSTANCE: MySingleton? = null
        fun getInstance(context: Context) =
            INSTANCE ?: synchronized(this) {
                INSTANCE ?: MySingleton(context).also {
                    INSTANCE = it
                }
            }
    }
    val requestQueue: RequestQueue by lazy {
        // applicationContext is key, it keeps you from leaking the
        // Activity or BroadcastReceiver if someone passes one in.
        Volley.newRequestQueue(context.applicationContext)
    }
    fun <T> addToRequestQueue(req: Request<T>) {
        requestQueue.add(req)
    }
}



4. 사용하기

val url = "http://www.example.com"
// Formulate the request and handle the response.
val stringRequest = StringRequest(Request.Method.GET, url,
         Response.Listener<String> { response ->
            // Do something with the response
        },
        Response.ErrorListener { error ->
            // Handle error
        })
val queue = MySingleton.getInstance(this.applicationContext).requestQueue
queue.add(stringRequest)



- 깃허브 주소 : https://github.com/google/volley

1. build.gradle(project)

dependencies {
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.4'
}


2. build.gradle(app)

plugins {
id 'com.google.android.gms.oss-licenses-plugin'
}
dependencies {
implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'
}


3. 액티비티 호출

startActivity(Intent(this, OssLicensesMenuActivity::class.java))
OssLicensesMenuActivity.setActivityTitle("화면 이름")



깃허브 주소 : https://github.com/google/play-services-plugins/tree/master/oss-licenses-plugin

'개발 > 안드로이드_Kotlin' 카테고리의 다른 글

[Kotlin] 문법 정리  (0) 2022.06.13
Volley 사용법  (0) 2022.06.12

+ Recent posts