1

Is it possible to detect when I launch an application and it gets closed as a result of the user pressed the back key?

If there's a solution to my question, I'll start a bounty (It takes 24 hours) and I'll reward it to the accepted answer, thank you in advance.

Ashraf Alshahawy
  • 1,139
  • 1
  • 14
  • 38
  • That's impossible. – Xaver Kapeller Mar 31 '16 at 03:28
  • Thanks, even startActivityForResult couldn't tell if the application I opened is closed as a result of using the back key? – Ashraf Alshahawy Mar 31 '16 at 03:31
  • In my case, I want to open the video player with video file, and I want to differentiate between when it gets closed as the video is fully played or the user pressed the back key. – Ashraf Alshahawy Mar 31 '16 at 03:34
  • No any button presses like home or back cannot be captured in third party applications. – Xaver Kapeller Mar 31 '16 at 03:35
  • Do you have any suggestion or workaround based on my scenario? – Ashraf Alshahawy Mar 31 '16 at 03:35
  • 1
    Then check if the video player gives you any information in the result code or data sent back to your application when you start the video player with `startActivityForResult`. – Xaver Kapeller Mar 31 '16 at 03:37
  • onActivityResults gets called immediately after using startActivityForResult, available solutions for this issue is not working, I'll keep searching to find how to fix this and check if startActivityForResult will help determine the reason of video player close. – Ashraf Alshahawy Mar 31 '16 at 14:55
  • What? `onActivityResult` definitely does not get called immediately. It gets called once the user returns to your `Activity`. – Xaver Kapeller Apr 01 '16 at 09:26
  • This is the normal behaviour, but sometimes it gets called immediately for multiple reason as the ones here: http://stackoverflow.com/questions/7910840/android-startactivityforresult-immediately-triggering-onactivityresult And here: http://stackoverflow.com/questions/3354955/onactivityresult-called-prematurely And for sorry non of provided answers fixes the immediate call to onActivityResult in my case, mostly because I'm using startActivityForResult from ArrayAdapter used for my custom listview ... I still don't know the reason but I'll keep searching and trying. – Ashraf Alshahawy Apr 01 '16 at 14:42
  • For some reason, the problem is fixed (I don't know how, maybe it was a hiccup of something), still onActivityResult receives nothing that the code I set when I used startActivityForResult ... So I still can't determine the reason of video player exit ... As a last resort I'm afraid I'm gonna have to reinvent the wheel and create a video player within my application. – Ashraf Alshahawy Apr 01 '16 at 14:54

0 Answers0