Intent extras 에 Hashtable 넘길 때

인텐트로 해시테이블 데이타를 passing 할 때 방법입니다.

인텐트에 해시테이블을 넘길 때
// A.class
Hashtable m_hash = new Hashtable();
m_hash.put("1", "aimh" );
m_hash.put("2", "tcher" );
m_hash.put("3", "picomax" );

Intent intent = new Intent(this, B.class);
intent.putExtra("data", m_hash);


해시테이블 데이타를 받을 때
// B.class
Serializable m_data = getIntent().getSerializableExtra("data");
Hashtable m_hash = new Hashtable((HashMap)m_data);
//m_hash.get("1");
//m_hash.get("2");
//m_hash.get("3");

Posted by Tcher

2010/02/22 13:42 2010/02/22 13:42
, , ,
Response
No Trackback , No Comment
RSS :
http://blog.inculab.net/rss/response/32

Trackback URL : http://blog.inculab.net/trackback/32

Leave a comment
[로그인][오픈아이디란?]
인텐트를 가장 많이 사용하는 형태는 다음과 같이 다른 Activity 로 message 를
전달 하는 형태다.

 
1)
Intent intent = new Intent(this, A.class);
startActivity(intent);
위 코드는 다음과 같이도 구현이 가능하다.

2)
Intent intent = new Intent();
intent.setClassName(this, "com.inculab.android.Test.A") // full package path 사용
startActivity(intent);

다른 점을 보자면
1) 은 Class 를 직접 인자로 취하는 거고 2)는 String 을 인자로 취한다.

Login 을 구현할 일이 있었는데
Login 을 하고 난 이후 redirect activity 기능이 필요했다.
A 라는 Activity 에서 LoginForm Activity 에 메시지를 보내고
LoginForm Activity 에서는 A 에서 보낸 redirect activity 인 B Activity 로 다시
메시지를 보낸다.

// A.java
Intent intent = new Intent(this, LoginForm.class);
intent.putExtra("redirect_url", "com.inculab.android,Test.B");
startActivity(intent);

// LoginFom.java
Intent intent = getIntent();
String m_redirect_url = intent.getStringExtra("redirect_url");

Intent intent2 = new Intent();
intent2.setClassName(this, m_redirect_url);
startActivity(intent2);

LoginForm 에서 1) 과 같이 Class 를 바로 전달 하면 좋겠지만
intent 에서 받아 올 때 는 String, Float, Integer, Bundle 형태만 지원하는 것 같다.
String 형태로 받아 올 경우 2) 와 같이 처리하면 된다.


Posted by Tcher

2010/02/18 10:29 2010/02/18 10:29
, ,
Response
No Trackback , No Comment
RSS :
http://blog.inculab.net/rss/response/31

Trackback URL : http://blog.inculab.net/trackback/31

Leave a comment
[로그인][오픈아이디란?]

블로그 이미지

- Tcher

Notices

Site Stats

Total hits:
24425
Today:
55
Yesterday:
117