Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-16360

Android: trayClickFocusedApp event not fired when push notification clicked in tray

    Details

      Description

      When a view is opened and app is placed into background, tapping on a push notification does not fire the trayClickFocusedApp event. This works fine if I don't open a window in the app. However, if even a single window is opened, trayClickFocusedApp stops working (I'm guessing this is due to the fact that there are more than a single activity if windows are opened). In the attached test code, simply comment out the following line and trayClickFocusedApp to start working again:

       win.open(); 

      Steps to reproduce

      1. Create a cloud enabled app
      2. Paste the following into app.js

        var win = Titanium.UI.createWindow({
        	title: 'Push Test',
        	backgroundColor: '#fff'
        });
         
        var login = ""; // Replace with an ACS user login
        var password = ""; // Replace with an ACS user password
         
        // If you comment out this line, everything works as expected
        win.open();
         
         
         
        // --------------------------------------------------------------------------------
        //
        // Push notification stuff
        //
        // --------------------------------------------------------------------------------
         
        var CloudPush = require('ti.cloudpush');
        CloudPush.debug = true;
        CloudPush.enabled = true;
         
        var deviceToken;
        var Cloud = require('ti.cloud');
         
        CloudPush.retrieveDeviceToken({
        	success: function deviceTokenSuccess(e) {
        		Ti.API.info('Device Token: ' + e.deviceToken);
        		deviceToken = e.deviceToken;
        		loginDefault(deviceToken);
        	},
        	error: function deviceTokenError(e) {
        		Ti.API.error('Failed to register for push! ' + e.error);
        	}
        });
         
        function loginDefault(e) {
         
        	Cloud.Users.login({
        		login: login,
        		password: password
        	}, function(e) {
        		if (e.success) {
         
        			defaultSubscribe();
         
        			//Place app in background
        			Ti.Platform.openURL("http://www.appcelerator.com");
         
        			//Send a push in 2 seconds
        			setTimeout(function() {
        				Cloud.PushNotifications.notify({
        					channel: 'message',
        					payload: {
        						"badge": 2,
        						"sound": "default",
        						"alert": "Push Notification Test",
        						"icon": "app_icon"
        					}
        				}, function(e) {
        					if (e.success) {
        						Ti.API.info('Success notify');
        					} else {
        						Ti.API.error('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
        					}
        				});
        			}, 2000);
        		} else {
        			Ti.API.error('Error:\\n' + ((e.error && e.message) || JSON.stringify(e)));
        		}
        	});
         
        }
         
        function defaultSubscribe() {
         
        	Cloud.PushNotifications.subscribe({
        		channel: 'message',
        		device_token: deviceToken,
        		type: 'gcm'
        	}, function(e) {
        		if (e.success) {
        			Ti.API.info('Subscribed!');
         
        			CloudPush.addEventListener('callback', function(evt) {
        				Ti.API.info("callback" + JSON.stringify(evt));
        				alert('got the callback event');
        			});
         
        			CloudPush.addEventListener('trayClickFocusedApp', function(evt) {
        				Ti.API.info('Tray Click Focused App (app was already running)' + JSON.stringify(evt));
        				alert('got the trayClickFocusedApp event')
        			});
        		} else {
        			Ti.API.error('Error:' + ((e.error && e.message) || JSON.stringify(e)));
        		}
        	});
        }
        

      3. Set your login/password to a valid user (lines 6 & 7)
      4. Launch the app on a device. The app should launch, fire off a push notification then go into the background by launching the browser.
      5. Tap the notification to return to the app.

      Expected Results

      The trayClickFocusedApp event listener should run and display a message.

      Actual Results

      The trayClickFocusedApp event listener does not run.

      Additional Info

      Here is the Q&A Post. Unfortunately, after 6 days, there has been no further clues.

      This comment on TIMODOPEN-320 is what lead me to believe there could be an issue with how app backgrounding is tracked when there are multiple activities.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jalter Jon Alter
                Reporter:
                mgumbs Mahlon Gumbs
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-18314
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Source Code