I have an app that needs to display some PDF files. The files are local to the device and the device is used in high-security locations with no web access.
Until Android gets some native ability or libraries to display a PDF file I'm relying on the AdobeReader.apk, which I fire off thusly:
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 perfectly, but after I'm done displaying I want to stop it and return to my main app. The 'winning' answer on this S.O question said if I used a StartActivityForresult() I could do it with a finishActivity() But I couldn't get it to work (I don't see how it could work since there's no instance of the Activity we want to stop)
Still, I changed my StartActivity to:
((Activity)ctx).startActivityForResult(i, 33); //!! // 33 = arbitrary r.c.
This invoked the Adobe reader just fine, but doing a ...
((Activity)ctx).finishActivity(33);
...produced no result. I tried wrapping it in try/catch and there were no exceptions thrown.
What am I doing wrong and how do I do this right? Thanks in advance!