- 는. this 질문에 응답 한 방법에 따라,이 방법을 새로운 작업을 추가하려면 Manifest에 수동으로 추가하지 않고 새로운 활동을 생성합니다. [모든 활동은
AndroidManifest.xml
에 기재해야합니다.]
새로운 활동 이름 Activity2.java
을 작성한다고합시다. 새로운 활동에 새로운 레이아웃을 추가하려면, res/layout
폴더에 새 XML 파일을 추가, [당신의 새로운 활동의 레이아웃을 정의] activity2.xml
가
가, 새로운 활동에 새로운 레이아웃을 연결하려면 새로에서이 줄을 포함 말한다
setContentView(R.layout.activity2);
Activity2.java
을 만들어 그래서 다음과 같이 표시됩니다
public class Activity2 extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
}
}
2. 이제 Activity1.java
에서 Activity2.java
으로 일부 데이터를 보내려면 Bundles
을 사용해야합니다. 당신이 보내려면
그래서, Activity1
에서 String
이 Activity1.java
에서 다음과 같이 말한다 :
Intent nextActivity = new Intent(this, Activity2.class);
Bundle passData = new Bundle(); //to hold your data
passDataBndl.putString("fname", fname); //put in some String. the first parameter to it is the id, and the second parameter is the value
nextActivity.putExtras(passDataBndl); //Add bundle to the Intent
startActivityForResult(nextActivity, 0); //Start Intent
이 (말 onCreate()
를) 다음
Bundle params = this.getIntent().getExtras(); //gets the data from the Intent
String firstName = params.getString("fname"); //gets value of fname