「Android入門」Activity通信のサンプルコード

サンプルコード

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnOpen=(Button)this.findViewById(R.id.btnOpen);
btnOpen.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {

Intent intent=new Intent(MainActivity.this, OtherActivity.class);
Bundle bundle=new Bundle();
bundle.putString(“name", “yamada");
bundle.putInt(“age", 26);
intent.putExtras(bundle);
startActivity(intent);
}
});
}
}

Android

Posted by arkgame