I am displaying a pdf document in my android application. For that I followed from the link How to open a PDF from an Android app (in a separate PDF viewer app) . My pdf document size is of 30mb. So it is taking time to display it. Hence I need to display it asynchronously. I am new to asynchronous tasks. Please give me some idea on how to display the pdf asynchronously.
use ProgressDialog as follow
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginsEnabled(true);
progressDialog = ProgressDialog.show(Activity_PDF.this, "Loading",
"Please wait", true);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
super.onReceivedError(view, errorCode, description, failingUrl);
Toast.makeText(Activity_PDF.this, description,
Toast.LENGTH_SHORT).show();
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
super.onPageFinished(view, url);
}
});
// used to read PDF files from docs.google.com
webview.loadUrl("http://docs.google.com/gview?embedded=true&url="
+ stPdfLink);
First of all, it's not you the one who open this pdf. You open it with other application, so if rendering speed is low, the only thing you can do is select other app for openeing it. It's not your responsibility and in your case it's not related to asynchronous tasks at all. I think it will be usefull for you to read about Android Fundamentals first of all and get some more knowlege abour Android framework and how it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.