0

我有一段代码,我从 startActivityForResult 开始,但 onActivityResult 方法没有被命中,我已经输入了 Log.d 注释,所以我知道代码是否被命中是我的代码:

  public class myClass extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.store_selector);
    Button getStore = (Button)findViewById(R.id.getStore);

    getStore.setOnClickListener(buttonGetStoreOnClickListener);
}

Button.OnClickListener buttonGetStoreOnClickListener
= new Button.OnClickListener(){

    public void onClick(View arg0) {


    Intent intent = new Intent("com.blah.Blah.client.android.SCAN");
    intent.setPackage("com.blah.Blah");
    intent.putExtra("com.blah.Blah.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
    startActivityForResult(intent, 0);
    Log.d("debug tag", "started activity");
};
};  


@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
   Log.d("debug tag", "inside onActivityResult");
    if (requestCode == 0)
    {
        if (resultCode == RESULT_OK)
        {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            Log.i("debug tag", "contents: "+contents+" format: "+format);
            Intent myIntent = new Intent(this, Ads.class);
            myIntent.putExtra("key", contents);
            startActivity(myIntent);
            setContentView(R.layout.activity_ads);

            // Handle successful scan
        }
        else if (resultCode == RESULT_CANCELED)
        {
            // Handle cancel
            Log.i("xZing", "Cancelled");
        }
    }
}


};
4

1 回答 1

1

您可能需要在“com.blah.Blah”活动中调用 finish() 之前调用 setResult()

于 2012-10-09T20:27:14.787 回答