Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13339] Android: Add support for onUserLeaveHint for activities

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2013-09-09T20:50:09.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 19, 2013 Sprint 19 API, Release 3.2.0
ComponentsAndroid
Labelscommunity, module_api, qe-testadded
ReporterJesper Jonsson
AssigneeSunila
Created2013-02-28T15:44:47.000+0000
Updated2013-10-23T23:15:19.000+0000

Description

There isn't any good way to know if the user "pauses" an Android app. For example by hitting the home button. Listening for activity pause/resume for a multiple activity app can be really messy. Maybe also hook this feature into the Ti.App.pause(d) event? http://developer.android.com/reference/android/app/Activity.html#onUserLeaveHint()
	var win = Ti.UI.createWindow({
		   backgroundColor : 'red',
		   orientationModes : [Titanium.UI.PORTRAIT],
		   exitOnClose : true,
		   navBarHidden : true
		});
	
	win.addEventListener('open', function(){
		win.getActivity().addEventListener('userleavehint', function()
				{
			Ti.API.info("Activity USER_LEAVE_HINT!!!!");
			});
	});
		 
	win.addEventListener('click', function()
	{	
	   var secondWin = Ti.UI.createWindow({
	      backgroundColor : 'blue',
	      orientationModes : [Titanium.UI.PORTRAIT],
	      navBarHidden : true
	   });
	  
	   secondWin.open();
	});
	win.open();

Comments

  1. Jesper Jonsson 2013-04-04

    Pause/resume should only be called when you leave the app, for example pressing the home buttom.
     
       var win = Ti.UI.createWindow({
          backgroundColor : 'red',
          orientationModes : [Titanium.UI.PORTRAIT],
          exitOnClose : true,
          navBarHidden : true
       });
       
       win.addEventListener('click', function()
       {
          var secondWin = Ti.UI.createWindow({
             backgroundColor : 'blue',
             orientationModes : [Titanium.UI.PORTRAIT],
             navBarHidden : true
          });
        
          secondWin.open(); // Ti.App pause/resume will NOT fire here! Good!
       });
       win.open();
       
       Ti.App.addEventListener('pause', function()
       {
          Ti.API.log("PAUSE!!!!");
       });
       
       Ti.App.addEventListener('resume', function()
       {
          Ti.API.log("RESUME!!!!");
       });
       
  2. Sunila 2013-08-10

    This event is for the activity and will be fired when the activity goes to the background when opening the 'secondWin' which won't help providing the 'app' 'pause' event.
  3. Sunila 2013-09-04

    A new event 'userleavehint' is added to the activity https://github.com/appcelerator/titanium_mobile/pull/4647
  4. Paras Mishra 2013-10-10

    Verified fix on: Device : HTC desire V , Android version : 4.0.3 SDK: 3.2.0.v20131008154043 CLI version : 3.2.0 OS : MAC OSX 10.8.4 Alloy : 1.2.2 Appcelerator Studio, build: 3.2.0.201310092427 XCode : 5

JSON Source