이곳저곳 관심이 많아요
10. Intent : Implicit intent 본문
1. MainActivity_기본
package com.example.myapplication
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
findViewById<Button>(R.id.callButton).setOnClickListener {
val intent = Intent(Intent.ACTION_DIAL, Uri.parse("tel:(+82)01012345678"))
startActivity(intent)
}
}
}
2. MainActivity_let 사용
package com.example.myapplication
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
findViewById<Button>(R.id.callButton).setOnClickListener {
val intent = Uri.parse("tel:(+82)01012345678").let{ number->
Intent(Intent.ACTION_DIAL, number)
}
startActivity(intent)
}
}
}
'Programming > Android' 카테고리의 다른 글
11. Fragment (0) | 2021.12.07 |
---|---|
10. Intent : MainActivity <-> SubActivity 최종 (0) | 2021.12.05 |
11. RecyclerView : 리사이클러뷰 전체정리, ViewModel 적용 (0) | 2021.12.03 |
10. Intent : MainActivity -> SubActivity 값 전달 (0) | 2021.11.05 |
Comments