반응형
https://developer.android.com/reference/kotlin/android/content/Intent
Intent는 앱 구성 요소 간의 작업을 요청할 수 있는 메시지 객체
TestActivity.kt
package com.example.lotto
import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import kotlinx.android.synthetic.main.activity_test.*
class TestActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test)
button.setOnClickListener{
//메인 엑티비티를 실행하는 intent를 생성
// 명시적 Intent
val intent = Intent(this@TestActivity, MainActivity::class.java)
//intent를 사용하여 액티비티 시장
startActivity(intent)
}
}
// xml에 메소드 등록, 버튼 onclick에 해당 함수 설정함
fun goConstellation(view:View){
val intent = Intent(this@TestActivity, ConstellationActivity::class.java)
startActivity(intent)
}
// 암시적 Intent
// 역시 아이디없고 xml에서 직접 연결함
fun callWeb(view: View){
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("http://naver.com")))
}
}
반응형
'IT > Android' 카테고리의 다른 글
Kotlin] 안드로이드 스레드 만들기 (0) | 2020.03.17 |
---|---|
Kotlin] 안드로이드 처음 로딩화면 만들기 (0) | 2020.03.11 |
Kotlin] Datepicker 날짜 계산 (연, 월+1, 일) (0) | 2020.03.08 |
Kotlin] 외부저장소 저장 & 가져오기 (0) | 2020.03.05 |
Kotlin] 내부저장소 저장 & 가져오기 (2) | 2020.03.05 |
댓글