0

I'm starting a pdf reader from code like this:

public static final int MY_INTENT_FLAG = 1;
String documentName = "filename.pdf";
File file = new File(getFilesDir(), documentName);
if (file != null && file.exists()) {
   Uri filePathUri = Uri.fromFile(file);
   Intent intent = new Intent(Intent.ACTION_VIEW);
   intent.setDataAndType(filePathUri, "application/pdf");

   try {
      startActivityForResult(intent,MY_INTENT_FLAG);
   } catch (ActivityNotFoundException e) {...}
}

It works fine to open the document and read it. However, when I press the back button from the pdf reader onActivityResult() is not called. Why is this? Can it simply be because that particular pdf reader does not set a result code when finishing? I have Acrobat Reader on my device.

I want to know when I get back from the external Activity so that the user don't need to login again in this case.

Thank you for any input

Anna
  • 1
  • You may want to look at the accepted answer in this question: http://stackoverflow.com/questions/3542107/how-do-i-handle-the-back-button-when-startactivityforresult-is-active – James Black Jul 22 '11 at 13:09

2 Answers2

0

Why is this? Can it simply be because that particular pdf reader does not set a result code when finishing? I have Acrobat Reader on my device.

Yes, that would normally be the case.

For the result to be passed back, the child activity would need to call setResult() first, followed by a call to finish(). If it doesn't the "result" is not propagated back to the parent activity.

ptashek
  • 186
  • 2
  • 6
  • Is there then no way to monitor this? – Vanja Jul 22 '11 at 13:27
  • If you were somehow to obtain a handle to the activity started via startActivityForResult(), you could probably monitor its state in a background thread using isFinishing(). – ptashek Jul 22 '11 at 15:12
0

You can get a onActivityResult() method but you can not get the result from child activity because it is not returning result by setResult()

and you are telling you for check login so you have alternative ways to check the login

for example

You can save username and password to preference and you can read the login details from it If details present in it then user is login and if not then you can popup login screen to user.

Dharmendra
  • 33,296
  • 22
  • 86
  • 129
  • This worked for me. However I discovered a situation when it's not working: There is a check box "Use as standard for this action" which appears on the phone when opening the pdf reader. On checking this it doesn't work the second time pdf reader is opened (and all following times). – Vanja Jul 25 '11 at 10:52