簡體   English   中英

onActivityResult內的Android Studio startActivity

[英]Android Studio startActivity inside onActivityResult

我用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);
    }
}

運行該應用程序后,我從條形碼中獲取數據,然后顯示“不幸停止”

日志類別:04-22 16:50:05.663 24845-24845 / example.zxing E / AndroidRuntime:致命異常: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>

@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();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM