gpt4 book ai didi

java - Android Studio onActivityResult 中的 startActivity

转载 作者:行者123 更新时间:2023-12-01 11:38:10 25 4
gpt4 key购买 nike

我创建了一个带有 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:无法启动 Activity ComponentInfo{example.zxing/example.zxing.BrowserKotaLama}:java.lang.IllegalStateException:您需要在此 Activity 中使用 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>

在 list 顶部

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

关于java - Android Studio onActivityResult 中的 startActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29792416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com