Im hoping this is simple, but im fairly confused as to what is going on. I am launching a PDF from an Imagebutton in an android activity using a piece of code I copied from elsewhere in my app.
if (v==imagebutton20) {
File file = new File("/sdcard/documents/20.pdf");
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
}
catch (ActivityNotFoundException e) {
}
}
} //end of load
The pdf loads fine but when i press back the activity that launched the pdf isnt show, instead it returns to the activity before. I have tried commenting out the
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
but the same effect. What am i missing? Sorry but i couldnt make sense of the official android guide, must be having a thick day!
Even more confused as I have checked the manifest file, the .xml for the activity (Brain) and yet each time i load the pdf using the code above back takes me back to the wrong activity (main) in my app. I am calling the Brain activity from Main via an imageview, but that works fine. When i launch the PDF above from Brain the back button takes me to Main and not the launching activity Brain.
I am using the code above elsewhere in 2 other activites in my app and the back key behaves exactly as you want / expect. Thats why i started checking the mainfest file, but no idea what im missing.
ANY help would be ace please!
Thanks.
I cannot explain why the following worked, but in case anyone else has a similar issue I solved the problem by:
Simple and not really sure why it worked, but it did.
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.