Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1908] Android: contacts picker callbacks never fired if showContacts called from other context

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionFixed
Resolution Date2013-07-15T06:42:04.000+0000
Affected Version/sn/a
Fix Version/sRelease 3.0.0
ComponentsAndroid
Labelsandroid, defect, module_media, qe-port, qe-testadded
ReporterBill Dawson
AssigneeNeeraj Gupta
Created2011-04-15T03:05:19.000+0000
Updated2013-07-15T06:42:04.000+0000

Description

This is yet another context/activity issue.

failcase app.js:

/*global Ti, Titanium, alert, JSON */
Titanium.UI.setBackgroundColor('#000');
var win = Titanium.UI.createWindow({  
    title:'Test',
    backgroundColor:'#fff',
    fullscreen: true,
    exitOnClose: true
});

var btn = Ti.UI.createButton({
    title: 'contacts'
});
btn.addEventListener('click', function() {
    Ti.Contacts.showContacts({
        selectedPerson: function(){Ti.API.info('!!!!!!!!! SELECTED');}
    });
});

win.add(btn);
win.open();

So in this example, the button to open the picker is in a heavyweight window. But the button was placed there -- and the listener added -- from the root context.

Debugging in Eclipse, I can see that the picker activity onResult is not even hit.

If you move the code that creates the button/event listener into the heavyweight window's own JS file, it works.

If you look in our http://github.com/appcelerator/titanium_mobile/blob/android_native_refactor/android/modules/contacts/src/ti/modules/titanium/contacts/ContactsModule.java#L126"> ContactsModule.java on the line where we setup calling the picker activity (using TiActivitySupport), you can see we're using the activity of the context, which in our example above will be the root context and therefore not correspond to the Activity of the heavyweight window.

Comments

  1. Bill Dawson 2011-04-15

    (from [e56ed6aff77ddba5c17137bd2951a02b911ac1f7]) [#1908] Workaround for contact picker activity onResult not firing if wrong activity is starting the picker: pass in a proxy object that represents the correct context from which to start the picker activity. http://github.com/appcelerator/titanium_mobile/commit/e56ed6aff77ddba5c17137bd2951a02b911ac1f7"> http://github.com/appcelerator/titanium_mobile/commit/e56ed6aff77dd...

  2. Bill Dawson 2011-04-15

    (from [a83d7f5c23ce11c0897a963001a77ed786b1faa8]) [#1908] Better type checking for that optional proxy arg. Put back @contextspecific which I'd taken away while testing and forgot to put back before the last commit. http://github.com/appcelerator/titanium_mobile/commit/a83d7f5c23ce11c0897a963001a77ed786b1faa8"> http://github.com/appcelerator/titanium_mobile/commit/a83d7f5c23ce1...

  3. Bill Dawson 2011-04-15

    (from [c1a4898b161a2bf564ddab74f0d5a3db1c523b52]) [#1908] Workaround for contact picker activity onResult not firing if wrong activity is starting the picker: pass in a proxy object that represents the correct context from which to start the picker activity. http://github.com/appcelerator/titanium_mobile/commit/c1a4898b161a2bf564ddab74f0d5a3db1c523b52"> http://github.com/appcelerator/titanium_mobile/commit/c1a4898b161a2...

  4. Bill Dawson 2011-04-15

    (from [e9f9d363491f9fbec474a616503c5cde12d5babd]) [#1908] Better type checking for that optional proxy arg. Put back @contextspecific which I'd taken away while testing and forgot to put back before the last commit. http://github.com/appcelerator/titanium_mobile/commit/e9f9d363491f9fbec474a616503c5cde12d5babd"> http://github.com/appcelerator/titanium_mobile/commit/e9f9d363491f9...

  5. Junaid Younus 2012-08-21

    Tested on a Samsung Galaxy S2 using TiSDK 2.2.0v20120821095711, unable to reproduce the issue. Ticket marked as resolved.
  6. Anshu Mittal 2012-08-29

    Verified on: SDK:2.2.0.v20120828153312 Studio:2.1.2.201208281351 Devices: LGp970(v 2.2.2)
  7. Anshu Mittal 2012-08-29

    Verified on: SDK:2.2.0.v20120828153312 Studio:2.1.2.201208281351 Devices: LG-p970(v 2.2.2) Contacts picker callbacks are fired successfully.
  8. Priya Agarwal 2013-07-15

    Reopening just to update the label.
  9. Priya Agarwal 2013-07-15

    Updated label and verified with: Titanium Studio:3.1.2.201307091843 Titanium SDK: 3.1.2.v20130710144553 acs:1.0.3 alloy:1.1.3 npm:1.2.14 titanium:3.1.1 itanium-code-processor:1.0.1 OS: OSX 10.8 Device:iPhone4 (v 5.1), Galaxy Nexus (v 4.0.4) Xcode: 4.5.1 Contacts picker callbacks are fired successfully.

JSON Source