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

ANDROID: startActivityForResult callback is not executed

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Invalid
    • Affects Version/s: Release 2.0.1
    • Fix Version/s: None
    • Component/s: Android
    • Environment:

      Application type: mobile
      Titanium SDK: 2.0.2.GA
      Javascript Engine: V8
      Platform & version: Android 2.2
      Device: Simulator and Physical
      Host Operating System: Ubuntu 12.04
      Titanium Studio version:2.0.2.201205311912

      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

      app.js

      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

      console

      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

        Attachments

          Activity

            People

            • Assignee:
              sunila Sunila
              Reporter:
              jmacias Jesus Macias Portela
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

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

                  Git Integration