전달 하는 형태다.
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