简体   繁体   中英

onActivityResult not getting hit Android

I have a piece of code that i am starting with startActivityForResult but the onActivityResult method is not getting hit, I have put in Log.d comments so I know whether or not the code is being hit here is my code:

  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");
        }
    }
}


};

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM