티스토리 뷰


public class MainActivity extends Activity {


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

public void onButton1Clicked(View v)

{

Intent intent = new Intent(getApplicationContext(), MenuActivity.class);

intent.putExtra("title", "fucking"); //intent의 Extra가 munuactivity로 전달됨.

startActivityForResult(intent, 1001); //1001이라는 요청코드를 가지고 구분

}

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

// TODO Auto-generated method stub

if (data != null){

String name = data.getStringExtra("name");

Toast.makeText(getApplicationContext(), "recievevalue : " + name, Toast.LENGTH_LONG).show();

}

super.onActivityResult(requestCode, resultCode, data);

}





public class MenuActivity extends Activity {


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_menu);

Intent intent = getIntent();

if(intent != null){

String title = intent.getStringExtra("title");

Toast.makeText(getApplicationContext(), "recievevalue : " + title, Toast.LENGTH_LONG).show();

}

}

public void onButton1Clicked(View v)

{

//intent로 보내야 시스템이 알아들을 수 있음.

Intent intent = new Intent();

intent.putExtra("name", "mother");

setResult(RESULT_OK, intent);

finish();

}




-> Manifest에서 새로 만든 MenuActivity를 알림.





댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
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
글 보관함