Application closing on back button after viewing pdf by Intent.ACTION_VIEW

不羁岁月 提交于 2019-12-11 03:17:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!