将价值带入另一项活动

时间:2015-09-09 04:13:54

标签: android android-activity

 protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qrscanner);
        fragment = (BarcodeFragment)getSupportFragmentManager().findFragmentById(R.id.sample);

是否可以将我从(setScanResultHandler(this))获得的值带入另一个活动?

        fragment.setScanResultHandler(this);

2 个答案:

答案 0 :(得分:1)

语法就像这样

用于发送数据

 String data = getIntent().getExtras().getString("keyName");
 Intent intent = new Intent(ActivityOne.this, ActivityTwo.class);
 intent.putExtra("keyName","value");

在ActivityTwo上接收

String value= getIntent().getStringExtra("keyName");
Intent intent = getIntent();
Bundle extras = intent.getExtras();

答案 1 :(得分:0)

如下所示

Intent intent=new Intent(this,SecondActivity.class);
intent.putExtra("ValueName","value");
startActivity(intent);

将valueid分配给ValueName,将值分配给值