I have an application that should display some PDF files. Files are local to the device, and the device is used in highly secure locations without network access.
Until Android gets some native features or libraries for displaying a PDF file, I rely on AdobeReader.apk, which I run as follows:
Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.fromFile(dgfile), "application/pdf"); i.setClassName("com.adobe.reader", "com.adobe.reader.AdobeReader"); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); // ctx is a passed-in Context of my main Activity try { ctx.startActivity(i); } catch (ActivityNotFoundException e) { // incase no viewer installed Log.e("DG_External", "No viewer found!"); }
This works fine, but after I finish showing, I want to stop it and return to the main application. The βwinningβ answer to this question SO said that if I used StartActivityForresult (), I could do it with the finishActivity () function, but I could not get it to work (I donβt see how this can work, since there is no instance Activity we want to stop)
However, I changed my StartActivity to:
((Activity)ctx).startActivityForResult(i, 33); //!! // 33 = arbitrary rc
This caused the Adobe reader to be just fine, but ...
((Activity)ctx).finishActivity(33);
... did not give a result. I tried wrapping it in try / catch and there were no exceptions.
What am I doing wrong and how can I do it right? Thanks in advance!
source share