onActivityResult中的Android Studio startActivity

时间:2015-04-22 08:55:00

标签: java android android-studio

我用Zxing条形码创建了一个项目

我正在使用:

onActivityResult()

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Intent toStart = null;
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if(result != null) {
        if(result.getContents() == null) {
            Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this, "Procces..: " + result.getContents(), Toast.LENGTH_LONG).show();

          toStart=new Intent(this,BrowserKotaLama.class);
          // result.getContets() --> is link URL 
         //  Here i want to open new activity with Webview
         // and Webview open that  url 
         // 

        }
    } else {
        // This is important, otherwise the result will not be passed to the fragment
        super.onActivityResult(requestCode, resultCode, data);
    }

    if (toStart!=null){
        startActivity(toStart);
    }
}

运行应用程序后,我从条形码中获取数据然后再获取数据 显示"不幸停止"

Log Cat: 04-22 16:50:05.663 24845-24845 / example.zxing E / AndroidRuntime:FATAL EXCEPTION:main     java.lang.RuntimeException:无法启动活动ComponentInfo {example.zxing / example.zxing.BrowserKotaLama}:java.lang.IllegalStateException:您需要对此活动使用Theme.AppCompat主题(或后代)。

的Manifest.xml

<application
    android:allowBackup="true"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:icon="@drawable/icon"
    android:label="@string/app_name" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".BrowserKotaLama"
        android:label="@string/title_activity_browser_kota_lama"
        android:parentActivityName=".MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="example.zxing.MainActivity" />
    </activity>
</application>

在清单顶部

 ?xml version="1.0" encoding="utf-8"?>
 manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.zxing" >

<uses-permission android:name="android.permission.INTERNET" />

样式      

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

</style>

1 个答案:

答案 0 :(得分:1)

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK) {
        setScanningMode(true);
        SCANNING_RESULT = data.getStringExtra("SCAN_RESULT");
        setResultOfScanning(SCANNING_RESULT);

    } else if (resultCode == RESULT_CANCELED) {
        SCANNING_RESULT = null;
        Toast.makeText(this, "Scanning Cancelled....", 500)
                .show();
    }
}