반응형
activity 3개가있다
1 activity에서 putExtras를 하면
2 activity에서는 받을 수 있지만
3 activity에서는 받을 수 없다
그런고로 2에서도 1에서 받은 data를 putExtra해주면 되겠다.
- 나는 이렇게 햇는데 다른방법이있을까? ㅡㅡ
1 activity - onClick 시에 putExtras로 데이터를 저장시킨다. activity name은 편의상 123 이라고 슴
final EditText num = (EditText)findViewById(R.id.num); Button start = (Button)findViewById(R.id.startBtn); start.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(1.this, 2.class); intent.putExtra("Num", num.getText().toString()); startActivity(intent);
2 activity - getExtras해서 1 에서 받아온다 그리고 str로 저장해줌 그리고 str을 putExtras 해서 3으로 날려준다
이때 str은 전역변수로 설정하기 위해 하늘나라로 가있다 (onCreate위에 private String str; 로 설정중)
final Intent in = getIntent(); str = in.getStringExtra("Num"); public void run() { Intent intent = new Intent(2.this, 3.class); intent.putExtra("Num1", str); startActivity(intent);
3 activity - 2와 마찮가지임. 전역변수 설정해서 str1 으로 get 해온다음에 사용하면 됨.
Intent intent = getIntent(); str1 = intent.getStringExtra("Num1");
putExtras 는 이거뿐이지만
getExtras는 경우에 따라 boolean, int 등으로 쓸 수도 있다
getStringExtras - 이런식으로 ㅇㅇ
아무튼 activity 간 데이터 전송할때 activity 를 하나 건너 뛸순 없나봄 ㅇa
반응형
'휴지통 > 휴지통2' 카테고리의 다른 글
develop launcher ex (0) | 2014.08.22 |
---|---|
포토샵 안열고 색상 뽑아내는 사이트 (0) | 2013.09.10 |
android 뒤로가기 버튼 "종료 하시겠습니까?" (0) | 2012.04.14 |
webview 와 javascript 호환? (0) | 2012.04.14 |
웹뷰 progressbar 오류 해결 (0) | 2012.04.14 |
댓글