Search code examples
titaniumappcelerator

Appcelerator: Detect when user presses home button (iOS & Android)


I want to detect when the user presses the home button in Android and iOS and then logout from the session. Is there any way to do that?

On iOS I tried to use the Titanium.App.pause listener and it works when I press the home button, but the problem is that this listener is also triggered when I do other things inside the app, like opening the gallery or the camera from the app or even using the control center.

On Android I tried a similar thing. But I'm facing the same problem.


Solution

  • There is subtle difference between pause and paused eventlisteners. Paused only detect when pressed home button on iPhone while pause always trigger when there is some interruptions into app like showing alert. Have a look into docs. http://docs.appcelerator.com/platform/latest/#!/api/Titanium.App-event-pause http://docs.appcelerator.com/platform/latest/#!/api/Titanium.App-event-paused

    You can use whatever depending upon your requirement. For Android have look into this post that might be helpful for pause/resume Android.

    http://www.tidev.io/2014/01/28/paused-resumed-events-on-android/