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

Android: onNewIntent event not being thrown

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Android
    • Labels:
    • Sprint:
      2015 Sprint 13 SDK

      Description

      Issue

      When calling an intent the onNewIntent event is not being thrown.

      Test case

      var win = Ti.UI.createWindow({fullscreen:false});
       
      //create some simple UI
      var textfield = Ti.UI.createTextField({width:300, height:'auto', top:40, left:20, hintText:'enter message'});
      var button = Ti.UI.createButton({title:'Send Notification', width:'auto', top:120, left:20, height:'auto'});
      var label = Ti.UI.createLabel({width:'auto', top:200, left:20, height:'auto', width:200, text:'Message from intent:'});
      var msgLabel = Ti.UI.createLabel({width:'auto', top:240, left:20, height:'auto', width:200, backgroundColor:'lightgrey', text:'---'});
       
      win.add(textfield);
      win.add(button);
      win.add(label);
      win.add(msgLabel);
       
      win.addEventListener("open", function(evt) {
           button.addEventListener("click", function(evt) {
              //handle the pending intent from the notification bar
           win.activity.addEventListener("newIntent", function(evt)
              {
                  var pushObjStr = evt.intent.getStringExtra("pushReceived"); //  ***** GET
                  if (pushObjStr) {
                      Ti.API.debug("received data: " + pushObjStr);
                      msgLabel.text = pushObjStr;
                  } else {
                      Ti.API.debug("no data received");
                      msgLabel.text = "no data received";
                  }
              });
               
              Ti.UI.Android.hideSoftKeyboard();
              msgLabel.text = "---"; //reset any previous text value
       
              //grab the user input
              var message = textfield.value;
              if (!message) {
                  alert('you must provide a message');
                  return;
              } else {
                  //clear out what was typed
                  textfield.value = '';
              }
               
              //put some custom data into an intent
              var intent = Ti.Android.createIntent(
              {
                  action: Ti.Android.ACTION_MAIN,
                  flags: Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP,
                  className: "org.appcelerator.titanium.TiActivity",
                  packageName: Ti.App.id
              });
              intent.addCategory(Ti.Android.CATEGORY_LAUNCH);
              intent.putExtra("pushReceived", message); //***** PUT
           
              //a pending intent to send open an activity when launched                        
              var pending = Ti.Android.createPendingIntent(
              {
                  activity: win.activity,
                  intent: intent,
                  //updateCurrentIntent: false,
                  type: Ti.Android.PENDING_INTENT_FOR_ACTIVITY
              });
           
              //put a notification in the notification bar                        
              var notification = Ti.Android.createNotification(
              {
                  contentIntent: pending,
                  contentTitle: "New Notification",
                  contentText: "Msg: " + message,
                  tickerText: "New Notification"
              });
              Ti.Android.NotificationManager.notify(1, notification);
          });
       
      });
       
      win.open();
      

      Steps to reproduce

      1. Run the test case
      2. Introduce a message in the textfield
      3. Press the send button

      Expected Result
      After receiving the local notification the message textfield will throw the newIntent event and show the sent message or a "No data received" message

      Actual Result
      The newIntent event is not thrown

        Attachments

          Activity

            People

            • Assignee:
              hpham Hieu Pham
              Reporter:
              mcota Marco Cota (Inactive)
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

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

                  Git Source Code