그러냐

intent 값 전달 본문

android

intent 값 전달

관절분리 2017. 11. 9. 14:46
반응형

[String]


먼저 Main에서 

Second Activity로

전환하면서

putExtra로

String값을 보낸다

public class MainActivity extends ActionBarActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

String str = "hi";

Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("itpangpang",str);
startActivity(intent);
}
}


SecondActivity에서

값을 받는다.

public class SecondActivity extends ActionBarActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Intent intent = getIntent();
Log.d("ITPANGPANG",intent.getExtras().getString("itpangpang"));
}
}



출처: http://itpangpang.xyz/125 [ITPangPang]

반응형