我使用zxing 扫描仪来扫描条形码和二维码,因为它是开源的。它工作正常,除了在选项卡中意味着我在选项卡组中使用了相同的代码,但在这里它不起作用。问题是 onActivityResult() 没有被调用。我们该如何解决这个问题。
code
子活动
public class ScannScreenActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.scan, null);
this.setContentView(viewToLoad);
mShowCamBut.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
IntentIntegrator integrator = new IntentIntegrator(ScannScreenActivity.this);
integrator.initiateScan();
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null)
{
System.out.println("ScannScreenActivity FormatName:"+scanResult.getFormatName());
System.out.println("ScannScreenActivity Content:"+scanResult.getContents());
}
}
}
活动组
public class TabGroupActivity extends ActivityGroup
{
//......
........Some code
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == Activity.RESULT_OK)
{
ScannScreenActivity activity = (ScannScreenActivity) getLocalActivityManager().getCurrentActivity();
activity.onActivityResult(requestCode, resultCode, data);
}
}
}
日志
09-21 11:45:32.448: D/memalloc(10723): /dev/pmem: Unmapping buffer base:0x5239b000 size:8560640 offset:7024640
09-21 11:45:32.458: D/memalloc(10723): /dev/pmem: Unmapping buffer base:0x51f79000 size:4280320 offset:2744320
09-21 11:45:33.949: W/IInputConnectionWrapper(10723): showStatusIcon on inactive InputConnection
09-21 11:45:33.999: W/IInputConnectionWrapper(10723): InputConnection = android.view.inputmethod.BaseInputConnection@40dc2da0, active client = false