Class MyActivity: public void loadFormAsync(final String path) { AsyncTask openFormTask = new AsyncTask() { @Override protected Void doInBackground(Void... params) { openForm(path); return null; } @Override protected void onPostExecute(Void param) { } }; openFormTask.execute(); } public void loadForm(final Myform myForm) { pdfFile = new Document(); byte[] pdfData = myForm.getPDFByteArray(); try { int r = pdfFile.OpenMem(pdfData, null); if (r != 0) { throw new Exception("failed to load pdf"); } pdfFile.SetCache( Global.tmp_path + "/temp.dat" ); Global.def_view = 7; Global.render_mode = 2; Global.zoomLevel = 4.0f; Runnable runnable = new Runnable() { public void run() { pdfReader.PDFOpen(pdfFile, false, new VPDFListener(MyActivity.this)); m_thumb.thumbOpen(pdfReader.PDFGetDoc(), new VThumbListener(pdfReader)); } }; MyActivity.this.runOnUiThread(runnable); } catch (Exception e) { e.printStackTrace(); } } private void openForm(String path) { Runnable runnable = new Runnable() { @Override public void run() { closeForm(); pdfReader = new VPDFReader(MyActivity.this,null); } }; runOnUiThread(runnable); boolean opened = myApplication.openForm(path); // calling to class MyApplication Runnable runnable2 = new Runnable() { @Override public void run() { pdfLayer.addView(pdfReader); } }; runOnUiThread(runnable2); } public void closeForm() { if (pdfReader != null) { pdfReader.PDFClose(); pdfLayer.removeView(pdfReader); } pdfReader = null; pdfFile = null; } Class MyApplication: public boolean openForm(String path) { MyForm myForm = readFileFromPath(path); // Some code to decode the file setForm(myForm); return true; } public void setForm(MyForm myForm) { myActivity.loadForm(myForm); }