在菜单创建上启动应用程序

时间:2013-04-04 08:31:31

标签: android tabs barcode

我正在使用应用程序在我正在开发的应用程序中读取QR代码(条形码)。我的问题是我不希望在菜单创建时启动条形码(A TabActivity)。 要清楚:我以这种方式创建菜单

public void createMenu(int current) {
    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost(); // The activity TabHost
    TabHost.TabSpec spec;   // Resusable TabSpec for each tab
    Intent intent;  


    intent = new Intent().setClass(this, Scan.class);
    spec = tabHost.newTabSpec("scanner").setIndicator(null,res.getDrawable(R.drawable.barcode_scan)).setContent(intent);
    tabHost.addTab(spec);


    // Do the same for the other tabs
    intent = new Intent().setClass(this, Research.class);
    spec = tabHost.newTabSpec("research").setIndicator(null,
                              res.getDrawable(R.drawable.system_search))
                              .setContent(intent);
    tabHost.addTab(spec);
}

并且,在Scan类中,我有以下内容:

@Override
public void onStart(){
    super.onStart();
    setContentView(R.layout.scan);
    try {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // "PRODUCT_MODE for bar codes
        startActivityForResult(intent, 0);
    } catch (Exception e) {
        Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
        Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);
        startActivity(marketIntent);

    }
}

但是,在菜单设置中,条形码应用程序每次都会启动,即使选择了不是扫描仪的当前选项卡,也会跳过菜单显示。如何解决?

谢谢!

1 个答案:

答案 0 :(得分:0)

       @Override
    public void onStart(){
        super.onStart();
        setContentView(R.layout.scan);
        try {
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // "PRODUCT_MODE for bar codes
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
            Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);
            startActivity(marketIntent);

        }
}

将其更改为

@覆盖

public void onStart(){
    super.onStart();
    setContentView(R.layout.scan);

}