playMaker

Author Topic: Detect when app is not in focus?[SOLVED]  (Read 2883 times)

kiramarshiku

  • Playmaker Newbie
  • *
  • Posts: 10
Detect when app is not in focus?[SOLVED]
« on: November 17, 2017, 10:33:59 AM »
Is there anyway to detect if the application has gone in the background? I'm using the app run in background action but I still need to detect if the app has gone into the background. I've tried using the application pause system event but it just doesn't work at all. If I use it as a global event it'll just trigger right away before the FSM even does anything else and it doesn't even seem to trigger when the app is actually paused by going in background.
« Last Edit: January 19, 2018, 01:12:45 AM by jeanfabre »

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Detect when app is not in focus?
« Reply #1 on: November 21, 2017, 03:31:57 AM »
there is an application focus (see attached screenshot)


kiramarshiku

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Detect when app is not in focus?
« Reply #2 on: January 15, 2018, 02:08:02 PM »
I still haven't found a good answer to this. Does anyone know how to do this?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Detect when app is not in focus?
« Reply #3 on: January 16, 2018, 02:22:56 AM »
Hi,

I would have answered the same as Coxy17. What's not working with these system events? What device are you testing, or are you testing it in Editor?

 Bye,

 Jean

kiramarshiku

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Detect when app is not in focus?
« Reply #4 on: January 16, 2018, 10:41:58 AM »
I am testing in the editor and then on an android phone. Those system events don't work correctly at all for me. For example if I use application pause as a global event it just gets triggered right away when I hit the play button and it doesn't actually trigger when the game is paused like if it's in the background. Application focus doesn't work either, as it just triggers right away like the pause event and just gets triggered again almost anytime I click on a button or something in the game.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Detect when app is not in focus?
« Reply #5 on: January 17, 2018, 02:31:12 AM »
Hi,

 It's because the editor and devices behaves differently.

 For your editor to fire pause events, you must uncheck "run in background", and then to test it, simply switch from Unity to your Browser or Mail client, then go back to Unity, you will see that the pause event was indeed fired by Unity and PlayMaker.


Check the screencast below to see that it works ( provided you did turn off "run in background")



now, for Android, if that doesn't work, then It's likely more an issue with Unity not forwarding properly or the android device itself.

 Let me know how it goes,

 Bye,

 Jean

kiramarshiku

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Detect when app is not in focus?
« Reply #6 on: January 17, 2018, 10:59:28 AM »
Yeah my problem is that application pause triggers for no reason at the start, interrupting the starting FSM. This is the issue I was talking about: http://hutonggames.com/playmakerforum/index.php?topic=10381.0 . It seems like this is just a known issue with no solution or a reason why it happens.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Detect when app is not in focus?
« Reply #7 on: January 19, 2018, 01:12:33 AM »
Hi,

 It's a Unity thing unfortunatly. Just work around it. I would maintain a flag to check for the pause context ( switch the flag value everything you get a pause event, then you know if you are paused or not)

 Bye,

 Jean