1

我有一个资产类,它有一些字符串和一个整数计数。在按下按钮时,我设置计数并调用 startActivityForResult。一旦进入 onActivityResult 计数为 0。

public class MainActivity extends Activity {

private Button BtnScanBc;
private Asset CurrentAsset;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    BtnScanBc = (Button)this.findViewById(R.id.scan_btn_id);


    // Scan barcode button
    BtnScanBc.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Scan Barcodes
            Asset.setCount(8);
            Log.i("setOnClickListener - Count", CurrentAsset.getCount().toString());
            // Log 8
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            intent.getStringExtra("SCAN_RESULT");
            startActivityForResult(intent, REQUEST_CODE_BC_SCAN);

        }
    });  // End BtnScanBc

}  // End onCreate

// Handle activity results
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == REQUEST_CODE_BC_SCAN) {
        if (resultCode == android.app.Activity.RESULT_OK) {
            Log.i("onActivityResult - Count", CurrentAsset.getCount().toString());
            // Log 0
    }  // End if requestCode == REQUEST_CODE_BC_SCAN
}  // End onActivityResult

}  // End MainActivity class

代码已被剪切,可能有错误的语法。提前致谢。已经花了太多时间试图弄清楚这一点。

4

0 回答 0