Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAP 11. 액티비티와 인텐트.

Similar presentations


Presentation on theme: "CHAP 11. 액티비티와 인텐트."— Presentation transcript:

1 CHAP 11. 액티비티와 인텐트

2 안드로이드는 모바일 플랫폼의 일종인데 모바일 플 랫폼은 성능 낮은 CPU, 느린 속도의 메모리, 작은 화 면, 배터리 용량 등으로 일반적인 컴퓨터와는 실행 단위가 다르다.
컴퓨터의 실행 단위는 애플리케이션, 안드로이드에 서는 액티비티 단위로 실행된다.

3 4가지의 중요한 개념 애플리케이션(application) 액티비티(activities)
액티비티 스택(activity stack) 태스크(task)

4 애플리케이션 한 개 이상의 액티비티들로 구성된다. 하나의 애플리케이션은 .apk를 확장자로 갖는 하나 의 파일 안에 저장된다.
액티비티들은 애플리케이션 안에서 느슨하게 묶여 있다.

5 액티비티 애플리케이션을 구성하는 빌딩 블록 쉽게 말하면 “화면 하나”라고 생각하면 된다.
안드로이드에서는 다른 애플리케이션의 액티비티도 시작할 수 있다.

6 태스크 액티비티의 이력을 관리해주는 매커니즘을 태스크 라 부른다.
사용자가 액티비티를 호출할 때마다 액티비티 태스 크라는 장소에 쌓이게 된다. 안드로이드는 태스크를 액티비티가 쌓여있는 스택이라 하여 액티비티 스택 이라 표현한다.

7 액티비티 스택 스택의 맨 위 액티비티는 현재 실행되는 액티비티이 고 다른 액티비티를 실행하면 스택의 맨 위에 삽입 (push)된다. Back 키를 누르면 현재 액티비티를 제거(pop)하고 이전 액티비티로 되돌아 간다. 사용자가 방문한 액티비티들은 어딘가에 기억

8 멀티태스킹 동시에 여러 태스크를 실행 현재의 태스크를 배경(background)으로 보내고 다 른 태스크를 전경(foreground)에서 시작할 수 있다.

9 멀티태스킹의 예

10 인텐트 다른 액티비티를 시작하려면 액티비티의 실행에 필 요한 여러 가지 정보들을 보내주어야 하는데 이때, 사용하는 메시지가 인텐트(intent)이다. 안드로이드의 컴포넌트끼리 통신하기 위한 메시지 시스템

11 인텐트의 종류 명시적 인텐트(explicit intent) 암시적 인텐트(implicit intent)
“애플리케이션 A의 컴포넌트 B를 구동시켜라“와 같이 명확하게 지정 암시적 인텐트(implicit intent) “지도를 보여줄 수 있는 컴포넌트이면 어떤 것이라도 좋다”

12 명시적인 인텐트 실행하고자 하는 액티비티의 이름을 적어 준다.
호출자는 메인 액티비티 자신이고 NextActivity를 호출한다는 뜻이다. startActivity 메서드는 인텐트의 정보를 참조하여 현재 액티비티를 부모로 하는 NextActivity를 호출한다. 이런 식으로 인텐트에 호출할 대상 컴포넌트가 명시되어 있는 것을 명시적 인텐트라 한다. Intent intent = new Intent(this, NextActivity.class); startActivity(intent);

13 명시적인 인텐트 예제 여기서 두 개의 액티비티로 이루어진 애플리케이션 을 작성하여 보자. 첫 번째 액티비티는 Activity1, 두 번째 액티비티는 Activity2라고 하자.

14 레이아웃 파일 layout1.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_height="wrap_content" android:text="여기는 액티비티1입니다."/> <Button android:layout_width="wrap_content" android:text="액티비티2로 갑니다."/> </LinearLayout>

15 레이아웃 파일 layout2.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_height="wrap_content" android:text="여기는 액티비티2입니다"/> <Button android:layout_width="wrap_content" android:text="액티비티1으로 갑니다"/> </LinearLayout>

16 Activity1.java ... public class Activity1 extends Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(R.layout.layout1); Button b = (Button)findViewById(R.id.Button01); b.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(Activity1.this, Activity2.class); startActivity(intent); } });

17 Activity2.java public class Activity2 extends Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout2); Button b = (Button)findViewById(R.id.Button01); b.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } });

18 메니페스트 파일 ... <activity android:name=".Activity1"
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="Activity2" android:label="Activity2"></activity>

19 실행 결과


Download ppt "CHAP 11. 액티비티와 인텐트."

Similar presentations


Ads by Google