问题
I need to open a pdf file from an Activity
. Pdf is opened but when I press the back button, my application shuts down.It closes all together. There's no exception in logcat either. Below is my code. I have tried using newIntent.setFlags(FLAG_ACTIVITY_NEW_TASK)
; but it shows similar behavior.
Intent newIntent = new Intent(Intent.ACTION_VIEW);
newIntent.setDataAndType(path, "application/pdf");
newIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
try{
startActivity(newIntent);
}catch(ActivityNotFoundException ex){
Toast.makeText(this, "Please install a pdf viewer", Toast.LENGTH_LONG).show();
}
My calling activity back button code works fine if I don't open pdf.
@Override
public void onBackPressed() {
Intent intent = new Intent(current.this, previous.class);
startActivity(intent);
this.finish();
}
Is there a way to get back to calling activity after viewing pdf through Intent.ACTION_VIEW
?
回答1:
Remove this.finish();
and check.
来源:https://stackoverflow.com/questions/24052642/application-closing-on-back-button-after-viewing-pdf-by-intent-action-view