I’m writing a project to read pdf files. My main class uses this code to call the ReaderActivity class:
Intent it = new Intent(this, ReaderActivity.class);
startActivity(it);
And the ReaderActivity class is like below to read pdf files:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String mimetype = "application/pdf";
File file = new File(filepath);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), mimetype);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
When I successfully open the pdf, I press the “back” button and the view is black. When I press “back” again, it returns to the main class view. When the pdf opens, I want to press “back” button one time and return to the main class view. How can I do this?
You are calling
ReaderActivityand from then you are callingintent to Viewpdf..Now when you press back from pdf reading ..you come back to reader activity where you didn’t have any layout set so you see black screen..
First Thing
You should have directly called the view intent from your main activity.
BUT anyhow you created EXTRA activity for doing this..so you will have to remove that ReaderActivity as soon it is used so you can do that 2 ways..
1)
Or 2)
in
onPause()of ReaderActivityWrite
this.finish();