Googleのダンボール用のアプリケーションを開発しようとしていますが、公式SDKからサンプルをダウンロードしました。内部クラスで(スレッド管理するヘルパークラスであるべきである)ImageLoaderTaskUIのスレッドから段ボールサンプルのメソッドを呼び出す必要があります
class ImageLoaderTask extends AsyncTask<Pair<Uri, Options>, Void, Boolean> {
/**
* Reads the bitmap from disk in the background and waits until it's loaded by pano widget.
*/
@Override
protected Boolean doInBackground(Pair<Uri, Options>... fileInformation) {
Options panoOptions = null; // It's safe to use null VrPanoramaView.Options.
InputStream istr = null;
if (fileInformation == null || fileInformation.length < 1
|| fileInformation[0] == null || fileInformation[0].first == null) {
AssetManager assetManager = getAssets();
try {
istr = assetManager.open("andes.jpg");
panoOptions = new Options();
panoOptions.inputType = Options.TYPE_STEREO_OVER_UNDER;
} catch (IOException e) {
Log.e(TAG, "Could not decode default bitmap: " + e);
return false;
}
} else {
try {
istr = new FileInputStream(new File(fileInformation[0].first.getPath()));
panoOptions = fileInformation[0].second;
} catch (IOException e) {
Log.e(TAG, "Could not load file: " + e);
return false;
}
}
panoWidgetView.loadImageFromBitmap(BitmapFactory.decodeStream(istr), panoOptions);
try {
istr.close();
} catch (IOException e) {
Log.e(TAG, "Could not close input stream: " + e);
}
return true;
}
}
はpanoWidgetViewはパノラマのためのウィジェットであり、それは、この内部クラスを含むアクティビティ内で宣言されています。 Androidスタジオで私にこのエラーが表示されます: メソッドloadImageFromBitmapをUIスレッドから呼び出す必要があります。現在、推定されたスレッドはworkerです。 可能な解決策はありますか?
パーフェクト。バックグラウンドでUI操作を実行できません。ありがとう! – sgrumo
まさに! https://developer.android.com/reference/android/os/AsyncTask.html#onPostExecute(Result) –