[TIMOB-12209] Android: Accessing properties from contacts crashes the app
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-01-15T14:20:03.000+0000 |
Affected Version/s | Release 3.0.0 |
Fix Version/s | Release 3.1.0, 2013 Sprint 02 API, 2013 Sprint 02 |
Components | Android |
Labels | SupportTeam, qe-testadded |
Reporter | Nikhil Sharma |
Assignee | Ping Wang |
Created | 2013-01-04T16:51:34.000+0000 |
Updated | 2013-10-04T07:43:50.000+0000 |
Description
The application crashes when accessing the properties from contacts. The test case is provided below and crash logs are attached.
Steps to Repo
1. Run the below code in the app.js of your project. 2. The application crashes while trying to access the device contacts.
var win1 = Titanium.UI.createWindow({
title : 'Tab 1',
backgroundColor : '#fff'
});
var people = Ti.Contacts.getAllPeople();
Ti.API.info('Total contacts: ' + people.length);
Ti.API.info('All contacts: ' + JSON.stringify(people));
win1.open();
Additional details
tc2 attachment reproduces the issue as well. Target environment has been already in summary.Attachments
File | Date | Size |
---|---|---|
tc1_log | 2013-01-04T16:51:34.000+0000 | 38580 |
tc2 | 2013-01-04T17:00:31.000+0000 | 44891 |
Per the details in tc2, the property in question here is most certainly the "image" property. If you comment out the last 3 lines of the code in the tc2 content so it never attempts person["image"], then the crash will go away. This is not as apparent if you only review the code block listed in the "Steps to Repo" portion of this ticket.
Accessing the image property will trigger memory allocations. If the image is large it could lead out of memory crashes. If you wish to serialize the contact you may need to filter only the properties you care about. Example:
1) Stringifying the entire contacts array is not the only way this problem shows up - please review the code block in tc2 where the image property is attempting to be accessed in a loop and the problem will show up eventually. 2) Being able to access the image properties is a requirement so we can't solve the issue by avoiding the image property as a long term solution
PR: https://github.com/appcelerator/titanium_mobile/pull/3707
Not crashing any more. Environment used for verification - Titanium SDK: 3.1.0.v20130223030327 Titanium Studio:3.0.2.201302141201 Device: Samsung GALAXY Note Android 2.3.6