AsyncTask
であなたの仕事は、メインスレッド過負荷にならないだろう。この方法で、あなたのビットマップを作成します:
private class MyAsyncTask extends AsyncTask<String, Void, Bitmap> {
protected void onPreExecute() {
// Runs on the UI thread before doInBackground
// Good for toggling visibility of a progress indicator
progressBar.setVisibility(ProgressBar.VISIBLE);
}
protected Bitmap doInBackground(String... strings) {
// Some long-running task like downloading an image.
Bitmap = downloadImageFromUrl(strings[0]);
return someBitmap;
}
protected void onProgressUpdate(Progress... values) {
// Executes whenever publishProgress is called from doInBackground
// Used to update the progress indicator
progressBar.setProgress(values[0]);
}
protected void onPostExecute(Bitmap result) {
// This method is executed in the UIThread
// with access to the result of the long running task
imageView.setImageBitmap(result);
// Hide the progress bar
progressBar.setVisibility(ProgressBar.INVISIBLE);
}
}
をそして、あなたはmaintのスレッドで何かを実行する必要があるときに再びこの使用します。
を
MyActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
//Your code to run in GUI thread here
}//public void run() {
});
ありがとう、私はこれを試してみます。 –
私は何度も試しましたが、エラーになります。 textureviewからのビットマップの取得は、UI Threadで実行する必要があるためです。それで、他の方法で試してみませんか?私はそこにあることを願っています....ありがとう –
非同期タスクを呼び出す前にビットマップを取得し、そのタスクで重い仕事をしてください。これはあなたの問題を解決する? – GuilhermeFGL