{ "id": "92743", "key": "TIMOB-9377", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2013-03-03T15:03:39.000+0000", "created": "2012-06-04T00:03:45.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "android", "callback", "community", "exalture", "intent", "problem", "startActivityForResult" ], "versions": [ { "id": "13272", "description": "Release 2.0.1", "name": "Release 2.0.1", "archived": true, "released": true, "releaseDate": "2012-04-16" } ], "issuelinks": [], "assignee": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "updated": "2017-03-22T21:13:20.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "h2. Problem\r\n\r\nWhen you invoke external apps using startActivityForResult, callback function that must be executed to extract return info. It never happens until you close main Window.\r\n\r\nI have found that the problem comes in the way of how to create the main window. Specifically the problem is the parameter \"navBarHidden\". If you use it in Titanium.UI.createWindow, startActivityForResult goes wrong.\r\n\r\nh2. Test case\r\n\r\n{code:lang=javascript|title=app.js}\r\nvar win = Titanium.UI.createWindow({\r\n title: 'SelectFile',\r\n backgroundColor: '#fff',\r\n navBarHidden: true\r\n});\r\nvar selectFile = Titanium.UI.createButton({\r\n top: 10, left: 10, right: 10, height: 35, title: 'Select File'\r\n});\r\nwin.add(selectFile);\r\n\r\nwin.addEventListener('android:back', function(e) {\r\n\tTi.API.debug(\"You press back Button\");\r\n win.close();\r\n});\r\n\r\nwin.addEventListener('close', function(e) {\r\n\tTi.API.debug(\"main Window closed\");\r\n});\r\n\r\nwin.open();\r\n\r\nTi.API.debug(\"mainWindow open\");\r\n\r\nselectFile.addEventListener('click', function() {\r\nTi.API.debug(\"selectFile clicked\");\r\nvar intent = Ti.Android.createIntent({ \r\n\t\taction: Ti.Android.ACTION_GET_CONTENT, \r\n\t\ttype: \"*/*\", \t\t\r\n\t}); \r\n\tintent.addCategory(Ti.Android.CATEGORY_OPENABLE);\r\n\tvar chooser = Ti.Android.createIntentChooser(intent, \"Select File\");\t\r\n\ttry {\r\n\t\tTi.API.debug(\"Lets go with intent\");\r\n\t\tvar activity = Ti.Android.currentActivity.startActivityForResult(chooser, function(e) {\r\n\t\t\tTi.API.debug(\"e:\"+JSON.stringify(e));\r\n\t\t\tif (e.resultCode === Ti.Android.RESULT_OK){\r\n\t\t\t\tTi.API.debug(\"e.resultCode:\"+e.resultCode);\r\n\t\t\t\tTi.UI.createNotification({\r\n duration: Ti.UI.NOTIFICATION_DURATION_LONG,\r\n message: 'File selected'\r\n }).show();\r\n\t\t\t}\r\n \t}) \r\n\t} \r\n\tcatch(e) { \r\n\t\tTi.API.debug(e); alert(\"No app installed!\"); \r\n\t}\t\r\n});\r\n\r\n{code}\r\n\r\nh2. Logs\r\n\r\n{code:lang=none|title=console}\r\nW/PowerManagerService( 1997): Timer 0x0->0x0|0x0\r\nI/TiApplication( 7995): (main) [0,0] checkpoint, app created.\r\nI/TiApplication( 7995): (main) [85,85] Titanium 2.0.1 (2012/04/12 16:36 999c68a)\r\nI/TiApplication( 7995): (main) [180,265] Titanium Javascript runtime: v8\r\nI/TiRootActivity( 7995): (main) [0,0] checkpoint, on root activity create, savedInstanceState: null\r\nE/TiApplication( 7995): (KrollRuntimeThread) [414,414] APP PROXY: ti.modules.titanium.app.AppModule@414d7548\r\nD/TiAPI ( 7995): mainWindow open\r\nI/TiRootActivity( 7995): (main) [0,0] checkpoint, on root activity resume. activity = es.thinetic.a.AActivity@414fe110\r\nW/PowerManagerService( 1997): Timer 0x7->0x3|0x0\r\nD/TiUIView( 7995): (main) [143,143] Nativeview is null\r\nD/TiUIView( 7995): (main) [9,152] Nativeview is null\r\nD/TiAPI ( 7995): selectFile clicked\r\nD/TiAPI ( 7995): Lets go with intent\r\nD/KeyguardUpdateMonitor( 1997): handleTimeUpdate\r\nV/com.mobilityflow.animatedweather.services.UpdateService$ServiceThread( 3342): Timed alarm onReceive() started at time: 2012-06-04 09:02:01.434\r\nW/PowerManagerService( 1997): Timer 0x7->0x3|0x0\r\nD/KeyguardViewMediator( 1997): handleTimeout\r\nW/PowerManagerService( 1997): Timer 0x7->0x3|0x0\r\nD/TiAPI ( 7995): You press back Button\r\nD/TiAPI ( 7995): main Window closed\r\nD/TiAPI ( 7995): e:{\"resultCode\":-1,\"source\":{},\"intent\":{\"data\":\"file:///mnt/sdcard/fix_permissions.log\",\"flags\":0},\"requestCode\":1}\r\nD/TiAPI ( 7995): e.resultCode:-1\r\nI/TiRootActivity( 7995): (main) [0,0] checkpoint, on root activity resume. activity = es.thinetic.a.AActivity@414fe110\r\nD/TiUIView( 7995): (main) [27,27] Nativeview is null\r\nE/TiBaseActivity( 7995): (main) [256,283] Layout cleanup.\r\nW/PowerManagerService( 1997): Timer 0x7->0x3|0x3\r\n\r\n{code}\r\n\r\nh2. Discussions\r\n\r\nhttp://developer.appcelerator.com/question/137709/startactivityforresult-and-callback-function-problem", "attachment": [], "flagged": false, "summary": "ANDROID: startActivityForResult callback is not executed", "creator": { "name": "jmacias", "key": "jmacias", "displayName": "Jesus Macias Portela", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "jmacias", "key": "jmacias", "displayName": "Jesus Macias Portela", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "Application type: mobile\r\nTitanium SDK: 2.0.2.GA\r\nJavascript Engine: V8\r\nPlatform & version: Android 2.2\r\nDevice: Simulator and Physical\r\nHost Operating System: Ubuntu 12.04\r\nTitanium Studio version:2.0.2.201205311912", "comment": { "comments": [ { "id": "231828", "author": { "name": "andreperazzi", "key": "andreperazzi", "displayName": "André Perazzi", "active": true, "timeZone": "America/Los_Angeles" }, "updateAuthor": { "name": "andreperazzi", "key": "andreperazzi", "displayName": "André Perazzi", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-12-18T13:13:54.000+0000", "updated": "2012-12-18T13:13:54.000+0000" }, { "id": "240477", "author": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "body": "setting the property 'navBarHidden' in createWindow will create a new Activity and js context. The code Ti.Android.currentActivity here, refers to the app main activity and the callback won't get called until that activity is active.\r\nTo use the activity for the 'win', use 'win.getActivity()' instead of Ti.Android.currentActivity which will fix the problem", "updateAuthor": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "created": "2013-03-03T15:03:39.000+0000", "updated": "2013-03-03T15:03:39.000+0000" }, { "id": "414966", "author": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing ticket as invalid.", "updateAuthor": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2017-03-22T21:13:20.000+0000", "updated": "2017-03-22T21:13:20.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }