Java 陷入了一项艰巨的任务
我在一个任务中有一些奇怪的行为。我正在尝试将pdf异步加载到PDFView( 这是我的密码:Java 陷入了一项艰巨的任务,java,android,android-asynctask,pdfviewer,Java,Android,Android Asynctask,Pdfviewer,我在一个任务中有一些奇怪的行为。我正在尝试将pdf异步加载到PDFView( 这是我的密码: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutP
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_simple_fileview);
setupUI();
startFile();
}
private void startFile() {
if(FileUtilities.getFileExtension(file.getName()).equals("pdf")) {
new loadPDFTask(this).execute(file);
}else{
try{
VideoView mVideoView = (VideoView)findViewById(R.id.videoview);
mVideoView.setVisibility(View.VISIBLE);
Uri uri = Uri.parse(file.getAbsolutePath());
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();
mVideoView.start();
}catch (Exception e){
Log.e("Fehler", "Video konnte nicht geladen werden");
}
}
}
private void setupUI() {
String path = getIntent().getExtras().getString("file");
file = new File(path);
mNextFile = (ImageView)findViewById(R.id.next_file);
mPreviousFile = (ImageView)findViewById(R.id.previous_file);
pdfView = (PDFView) findViewById(R.id.pdfview);
}
//lädt PDF asynchron und zeigt ProgressDialog an
private class loadPDFTask extends AsyncTask<Object,String,File> {
private Context context;
public loadPDFTask(Context ctx){
context = ctx;
dialog = new ProgressDialog(context);
dialog.setMessage("Loading PDF...");
}
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog.show();
}
@Override
protected File doInBackground(Object... args) {
File file = (File)args[0];
pdfView.fromFile(file)
.defaultPage(1)
.showMinimap(false)
.enableSwipe(true)
.load();
return file;
}
@Override
protected void onPostExecute(File unused) {
super.onPostExecute(unused);
if(dialog!=null) {
dialog.dismiss();
}
}
}
似乎该库不应该进入异步任务。该库可能已经是异步的,因为它允许您注册一个onLoad回调。您是否尝试过按照该库的自述文件中的示例进行操作?只需在主线程中运行调用(不带异步任务),如果在加载完成后需要执行某些操作,请注册一个onLoad回调。其他异步任务正在等待,因为这项任务尚未完成。它尚未完成…或者pdf加载非常复杂(我使用过专业的pdf库,可以在具有几页的复杂体系结构pdf上运行30到几分钟)或者该库在某个地方陷入了无限循环。您可能必须调试该库。您确定pdf文件没有损坏或其他什么吗?您确定所创建的库尚未异步?我不明白您为什么需要线程池执行器,您只运行一个任务。如果您是r同时运行多个任务这仍然不会导致您遇到的问题。很可能库或文件有问题。在没有asynctask的情况下调用load函数时的行为相同…但是当我从主活动以外的另一个活动启动该活动时,它会像charm一样工作。我应该发布我的mainAc吗还有活力吗?
07-09 17:35:58.370 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x1e000001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:58.370 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 0.147222 0.000000 0.000000 -0.148148 0.000000 80.000000
07-09 17:35:58.370 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 106 80
07-09 17:35:58.370 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:58.490 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:58.490 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:35:58.520 10080-10098/lp.german.bischofshofpresenter.app D/dalvikvm﹕ GC_FOR_ALLOC freed 3520K, 26% free 14324K/19207K, paused 21ms
07-09 17:35:58.530 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x1ee00001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:58.530 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 1.066667 0.000000 0.000000 -0.948148 0.000000 256.000000
07-09 17:35:58.530 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 256 256
07-09 17:35:58.530 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:58.750 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:58.760 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:35:58.760 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x1fc00001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:58.760 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 1.066667 0.000000 0.000000 -0.948148 -256.000000 256.000000
07-09 17:35:58.760 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 256 256
07-09 17:35:58.760 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:58.990 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:58.990 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:35:59.000 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x20a00001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:59.000 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 1.066667 0.000000 0.000000 -0.948148 -256.000000 512.000000
07-09 17:35:59.000 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 256 256
07-09 17:35:59.000 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:59.080 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:59.090 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:35:59.090 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x21800001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:59.090 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 1.066667 0.000000 0.000000 -0.948148 0.000000 512.000000
07-09 17:35:59.090 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 256 256
07-09 17:35:59.090 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:59.260 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:59.260 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:35:59.270 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x22600001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:59.270 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 1.066667 0.000000 0.000000 -0.948148 -512.000061 256.000000
07-09 17:35:59.270 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 256 256
07-09 17:35:59.270 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:59.330 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:59.330 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:35:59.370 10080-10082/lp.german.bischofshofpresenter.app D/dalvikvm﹕ GC_CONCURRENT freed 3203K, 33% free 13048K/19207K, paused 2ms+4ms
07-09 17:35:59.370 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x23400001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:59.370 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 1.066667 0.000000 0.000000 -0.948148 -512.000061 512.000000
07-09 17:35:59.370 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 256 256
07-09 17:35:59.370 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:59.460 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:59.460 10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:36:05.700 10080-10080/lp.german.bischofshofpresenter.app D/OpenGLRenderer﹕ Flushing caches (mode 0)