2

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?

Lavekush Agrawal
  • 6,040
  • 7
  • 52
  • 85
user2244871
  • 51
  • 1
  • 3
  • 3
    Remove this `newIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);` – M D Jun 05 '14 at 06:00
  • @MD But i need this flag on my login activity; I have a button in login activity to show phone setting. when i press back on setting, application closed! How can i do now?! – Dr.jacky Jul 11 '14 at 13:21

1 Answers1

1

Remove this.finish(); and check.