• 인텐트(Intent)
- 액티비티 컴포넌트의 호출에 사용
• 액티비티의 호출
- startActivity(Intent)
인자로 받은 인텐트가 가리키는 액티비티 호출
- startActivityForResult(Intent, int requestCode)
호출하는 액티비티에서 결과를 받아야 할 때 사용
requestCode : 호출하는 액티비티를 구분함
• 액티비티 표시 과정

[새 액티비티 생성]
• 액티비티 호출 동작 구현 (IntentExample)
- Layout
Button 위젯 추가 (id=launch)
- Code
Button 위젯의 인스턴스 생성
Button 클릭시 동작을 구현할 onClickListener
인터페이스 구현
• Layout : 버튼 위젯 추가
- Layout Editor / Outline 창에서 위젯 추가

• Code : Button 위젯 인스턴스 생성
- findViewById(int resId)
해당 ID를 가지는 뷰의 인스턴스를 받아옴
뷰에 알맞게 캐스팅(Casting) 필요

• Code : Button의 동작을 처리할 인터페이스 구현 / 설정
- android.view.View.onClickListener
public void onClick(View v) 메소드 구현
- Button.setOnClickListener(View.onClickListener)
버튼을 클릭했을 때 동작을 구현한 인터페이스를 인자로 받음

• onClickListener 인터페이스 구현
- 다른 액티비티를 호출할 인텐트 생성

• onClickListener 인터페이스 구현
- 액티비티 호출

• 액티비티 호출 동작 구현 (Activity2)
- Layout
Button 위젯 추가 (id=terminate)
- Code
Button 위젯의 인스턴스 생성
Button 클릭시 동작을 구현할 onClickListener 인터페이스 구현
• onClickListener 인터페이스 구현
- 액티비티를 종료

댓글 없음:
댓글 쓰기