티스토리 뷰
Intent로 다른 Activity(예, AnotherActivity.class)를 실행시킬 때는 다음과 같이 한다.
Intent intent = new Intent(getApplicationContext(), AnotherActivity.class); startActivity(intent); |
그런데, 여기에 추가로 AnotherActivity 데이터를 전달하고 싶을 때가 있다.
이때 사용할 수 있는 것이 putExtra() 다.
Intent intent = new Intent(getApplicationContext(), AnotherActivity.class); intent.putExtra(“name”, “rio”); intent.putExtra(“age”, 10); startActivity(intent); |
그리고, AnotherActivity에서는 다음과 같이 getExtras()를 이용해서 데이터를 받을 수 있다.
(바로 데이터를 받을 것이므로 보통은 onCreate() 메서드에 구현 한다.)
Intent intent = getIntent(); String name = intent.getExtras().getString(“name”); int age = intent.getExtras().getInt(“age”); |
반응형
'언어 > ANDROID' 카테고리의 다른 글
[Android] 스크롤뷰 막고 Fragment 슬라이딩 하는법 (0) | 2016.09.01 |
---|---|
[Android] EditText에 phon 하이픈(-) 자동 넣기 (0) | 2016.09.01 |
[Android] 안드로이드 유효성 검사 (0) | 2016.09.01 |
[Android] 안드로이드 생명 주기 (0) | 2016.09.01 |
[Android] 문자열을 int로, int 문자열로 (0) | 2016.09.01 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- Class
- 스프링
- 클래스
- Server
- Delete
- mysql
- mybatis
- 자바
- 생성
- 안드로이드
- nsis
- Default
- 어노테이션
- js
- java
- 라이브러리
- 연결
- 사용
- Controller
- iNT
- jdbc
- jsp
- Android
- 종류
- UTF-8
- spring
- synchronized
- 음식
- 하기
- Create
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함