Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9377] ANDROID: startActivityForResult callback is not executed

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2013-03-03T15:03:39.000+0000
Affected Version/sRelease 2.0.1
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, callback, community, exalture, intent, problem, startActivityForResult
ReporterJesus Macias Portela
AssigneeSunila
Created2012-06-04T00:03:45.000+0000
Updated2017-03-22T21:13:20.000+0000

Description

Problem

When you invoke external apps using startActivityForResult, callback function that must be executed to extract return info. It never happens until you close main Window. I 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.

Test case

var win = Titanium.UI.createWindow({
    title: 'SelectFile',
    backgroundColor: '#fff',
    navBarHidden: true
});
var selectFile = Titanium.UI.createButton({
    top: 10, left: 10, right: 10, height: 35, title: 'Select File'
});
win.add(selectFile);

win.addEventListener('android:back', function(e) {
	Ti.API.debug("You press back Button");
        win.close();
});

win.addEventListener('close', function(e) {
	Ti.API.debug("main Window closed");
});

win.open();

Ti.API.debug("mainWindow open");

selectFile.addEventListener('click', function() {
Ti.API.debug("selectFile clicked");
var intent = Ti.Android.createIntent({ 
		action: Ti.Android.ACTION_GET_CONTENT, 
		type: "*/*", 		
	}); 
	intent.addCategory(Ti.Android.CATEGORY_OPENABLE);
	var chooser = Ti.Android.createIntentChooser(intent, "Select File");	
	try {
		Ti.API.debug("Lets go with intent");
		var activity = Ti.Android.currentActivity.startActivityForResult(chooser, function(e) {
			Ti.API.debug("e:"+JSON.stringify(e));
			if (e.resultCode === Ti.Android.RESULT_OK){
				Ti.API.debug("e.resultCode:"+e.resultCode);
				Ti.UI.createNotification({
                    duration: Ti.UI.NOTIFICATION_DURATION_LONG,
                    message: 'File selected'
                }).show();
			}
    	}) 
	} 
	catch(e) { 
		Ti.API.debug(e); alert("No app installed!"); 
	}	
});

Logs

W/PowerManagerService( 1997): Timer 0x0->0x0|0x0
I/TiApplication( 7995): (main) [0,0] checkpoint, app created.
I/TiApplication( 7995): (main) [85,85] Titanium 2.0.1 (2012/04/12 16:36 999c68a)
I/TiApplication( 7995): (main) [180,265] Titanium Javascript runtime: v8
I/TiRootActivity( 7995): (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
E/TiApplication( 7995): (KrollRuntimeThread) [414,414] APP PROXY: ti.modules.titanium.app.AppModule@414d7548
D/TiAPI   ( 7995): mainWindow open
I/TiRootActivity( 7995): (main) [0,0] checkpoint, on root activity resume. activity = es.thinetic.a.AActivity@414fe110
W/PowerManagerService( 1997): Timer 0x7->0x3|0x0
D/TiUIView( 7995): (main) [143,143] Nativeview is null
D/TiUIView( 7995): (main) [9,152] Nativeview is null
D/TiAPI   ( 7995): selectFile clicked
D/TiAPI   ( 7995): Lets go with intent
D/KeyguardUpdateMonitor( 1997): handleTimeUpdate
V/com.mobilityflow.animatedweather.services.UpdateService$ServiceThread( 3342): Timed alarm onReceive() started at time: 2012-06-04 09:02:01.434
W/PowerManagerService( 1997): Timer 0x7->0x3|0x0
D/KeyguardViewMediator( 1997): handleTimeout
W/PowerManagerService( 1997): Timer 0x7->0x3|0x0
D/TiAPI   ( 7995): You press back Button
D/TiAPI   ( 7995): main Window closed
D/TiAPI   ( 7995): e:{"resultCode":-1,"source":{},"intent":{"data":"file:///mnt/sdcard/fix_permissions.log","flags":0},"requestCode":1}
D/TiAPI   ( 7995): e.resultCode:-1
I/TiRootActivity( 7995): (main) [0,0] checkpoint, on root activity resume. activity = es.thinetic.a.AActivity@414fe110
D/TiUIView( 7995): (main) [27,27] Nativeview is null
E/TiBaseActivity( 7995): (main) [256,283] Layout cleanup.
W/PowerManagerService( 1997): Timer 0x7->0x3|0x3

Discussions

http://developer.appcelerator.com/question/137709/startactivityforresult-and-callback-function-problem

Comments

  1. André Perazzi 2012-12-18

  2. Sunila 2013-03-03

    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. To use the activity for the 'win', use 'win.getActivity()' instead of Ti.Android.currentActivity which will fix the problem
  3. Lee Morris 2017-03-22

    Closing ticket as invalid.

JSON Source