(kotlin) intent

박용석·2023년 11월 3일
  • Intent는 Android 어플리케이션 개발에서 사용되는 개념이다. 인텐트는 두 가지 기본적인 목적을 가지고 있다.
    1. 컴포넌트 간 통신
      • 인텐트는 액티비티, 서비스, 브로드캐스트 수신자 등 Android의 다양한 구성 요소 간에 통신할 때 사용한다.
    2. 동작 수행 지시
      • 인텐트는 액티비티, 서비스, 브로드캐스트 수신자 등 Android의 다양한 구성 요소 간에 통신할 때 사용합니다. 예를 들어, 다른 액티비티를 시작하거나, 서비스를 시작하거나, 브로드캐스트 메시지를 보내는 등의 작업을 수행할 수 있습니다.
    • 다른 액티비티 시작
      val intent = Intent(this, AnotherActivity::class.java)
      startActivity(intent)
    • 액티비티 시작 및 데이터 전달
      val intent = Intent(this, AnotherActivity::class.java)
      intent.putExtra("key", "value")
      startActivity(intent)
    • 웹페이지 열기
      val webpage = Uri.parse("http://www.example.com")
      val intent = Intent(Intent.ACTION_VIEW, webpage)
      startActivity(intent)
    • 전화 걸기
      val phoneNumber = Uri.parse("tel:123456789")
      val intent = Intent(Intent.ACTION_DIAL, phoneNumber)
      startActivity(intent)
    • 암시적 인텐트로 다른 앱에서 기능 실행
      val intent = Intent(Intent.ACTION_SEND)
      intent.type = "text/plain"
      intent.putExtra(Intent.EXTRA_TEXT, "Hello, this is a message!")
      startActivity(intent)
    • 서비스 시작
      val serviceIntent = Intent(this, MyService::class.java)
      startService(serviceIntent)
    • 브로드캐스트 메시지 보내기
      val intent = Intent("custom.action.MY_ACTION")
      			intent.putExtra("key", "value")
      			sendBroadcast(intent)
      	
profile
슬기로운 개발 활동

0개의 댓글