Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- Graphic
- HTML
- 에러페이지
- Java
- JavaScript
- Android
- 예외처리
- 생성자
- oracle
- paint
- layout
- 기본
- JSP
- 전화걸기
- 배열
- Menu
- 이클립스
- 어노테이션
- 국제화
- AWT
- 오버로딩
- 메소드
- OGNL
- Spring
- 메서드
- Eclips
- struts2
- 클래스
- mybatis
- 안드로이드
Archives
- Today
- Total
note
Intent 사용하여 화면 이동 본문
(manifest.xml 에서 application activity 추가해줘야됨)
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="이동" />
<Button
android:id="@+id/button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="데이터를 갖고 이동" />
</LinearLayout>
main_two.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kr.android.intent.msg"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".IntentMsg"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="IntentTwo"></activity>
</application>
</manifest>
package kr.android.intent.msg;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class IntentMsg extends Activity implements View.OnClickListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(R.id.button01);
Button button2 = (Button)findViewById(R.id.button02);
button.setOnClickListener(this);
button2.setOnClickListener(this);
}
public void onClick(View v){
Intent i = null;
if(v.getId() == R.id.button01){
i = new Intent(this,IntentTwo.class);
}else if(v.getId() == R.id.button02){
//Intent에 실행시킬 Activity 정보 저장
i = new Intent(this,IntentTwo.class);
//실행 시킨 Activity에서 사용할 데이터 셋팅
//사용할 데이터는 Bundle 객체가 생성된후 그 곳에 보관됨
i.putExtra("msg", "인텐트로 전달된 데이터");
}
//Intent객체가 가지고 있는 Activity 정보를 이용해서 Activity 생성,실행
startActivity(i);
}
}
package kr.android.intent.msg;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class IntentTwo extends Activity{
TextView view;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_two);
view = (TextView)findViewById(R.id.text);
view.setText("intentTwo 화면\n");
Intent i = getIntent();
if(i.getExtras() == null){
view.append("데이터 없이 화면 이동");
}else{
//Activity 실행시 데이터를 저장했다면 Bundle 객체로 부터 데이터 추출
Bundle b = i.getExtras();
String str = b.getString("msg");
view.append(str);
}
}
}
'Android > 기본' 카테고리의 다른 글
| 안드로이드 전화걸기 (0) | 2012.01.17 |
|---|---|
| 구글맵 사용하여 위도 경도값 직접입력해서 보기 (0) | 2012.01.17 |
| 구글맵에 마커 표시하기(위치 지정) (2) | 2012.01.17 |
| 구글맵 사용하기 (0) | 2012.01.17 |
| 이클립스 구글맵 api 설치하기 및 자신의 위치 알아내기(경도,위도) (0) | 2012.01.17 |