Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12412] Android: Ti.Android.currentActivity.intent.className and Ti.Android.currentActivity.intent.packageName are always undefined

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2016-05-25T04:36:50.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.4.0
ComponentsAndroid
Labelsexalture
ReporterDavide Cassenti
AssigneeHieu Pham
Created2013-01-24T11:36:42.000+0000
Updated2016-07-08T23:46:15.000+0000

Description

Problem description

The value of Ti.Android.currentActivity.intent.className and Ti.Android.currentActivity.intent.packageName is always undefined.

Steps to reproduce

This simple app will print out undefined in the logs:
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

var win1 = Titanium.UI.createWindow({
    title:'Tab 1',
    backgroundColor:'#fff',
    fullscreen: true
});
win1.open();

Titanium.API.info("Class name: " + Titanium.Android.currentActivity.intent.className());

Titanium.API.info("Package name: " + Titanium.Android.currentActivity.intent.packageName);

Comments

  1. jithinpv 2013-03-15

    an error is shown while running the test case Uncaught TypeError:Property'className'of object # is not a function jithinpv
  2. Sunila 2013-04-09

    As per the documentation, these are creation-only properties.
  3. Fokke Zandbergen 2016-02-24

    [~cng] can we reconsider this one? With TIMOB-19679 this has become relevant again because unless you create the intent in app.js/alloy.js you need the className/packageName of your app in order to create an alternative launch shortcut for it. Sunila mentions its creation only, but that doesn't say they cannot be read.
  4. Fokke Zandbergen 2016-03-11

    This was closed as Invalid because the properties are creation only, but that's not what the ticket is about. It is about being able to read the properties after creation, not change.
  5. Srikanth Sombhatla 2016-04-13

    PR: https://github.com/appcelerator/titanium_mobile/pull/7940 Use this test code
       // this sets the background color of the master UIView (when there are no windows/tab groups on it)
       Titanium.UI.setBackgroundColor('#000');
        
       var win1 = Titanium.UI.createWindow({
           title:'Tab 1',
           backgroundColor:'#fff',
           fullscreen: true
       });
       
       win1.open();
       
       Titanium.API.info("current activity: " + Titanium.Android.currentActivity);
       Titanium.API.info("Class name: " + Titanium.Android.currentActivity.intent.getClassName()); 
       Titanium.API.info("Package name: " + Titanium.Android.currentActivity.intent.getPackageName());
        
       
       
  6. Ashraf Abu 2016-04-14

    PR reviewed and merged. [~fokkezb] with this fixed, which other ticket is related to this?
  7. Fokke Zandbergen 2016-04-14

    [~msamah] Thanks, with this fixed TIMOB-19679 will be easier to implement for users, but that feature is still blocked by TIMOB-20459
  8. Ashraf Abu 2016-05-11

    Reverting this ticket: https://github.com/appcelerator/titanium_mobile/pull/7996 A bug was introduced in this PR where if you back out of the app using the back button and enter the app again, it will crash. Line causing bug is:- https://github.com/appcelerator/titanium_mobile/blob/50dec34783b243948ef3dfdde25750ef9ff478d8/android/titanium/src/java/org/appcelerator/titanium/proxy/IntentProxy.java#L63 https://github.com/appcelerator/titanium_mobile/blob/50dec34783b243948ef3dfdde25750ef9ff478d8/android/titanium/src/java/org/appcelerator/titanium/proxy/IntentProxy.java#L66 The crash occurs in the native code of android. Last debug point was in MessageQueue.class line 581:-
                   // We can assume mPtr != 0 because mQuitting is false.
                   if (needWake) {
                       nativeWake(mPtr);
                   }
       
    Will be leaving ticket open. [~fokkezb] Fyi.
  9. Ashraf Abu 2016-05-12

    Setting this for release 6.0.0 instead due to bug.
  10. Hieu Pham 2016-05-23

    master PR: https://github.com/appcelerator/titanium_mobile/pull/8013 Testing code:
        var win = Ti.UI.createWindow({
            backgroundColor : 'black',
            layout : 'vertical'
        });
        win.open();
        Ti.API.info("Class name: " + Titanium.Android.currentActivity.intent.getClassName());
        Ti.API.info("Class name: " + Titanium.Android.currentActivity.intent.className);
        
        Ti.API.info("Package name: " + Titanium.Android.currentActivity.intent.getPackageName());
        Ti.API.info("Package name: " + Titanium.Android.currentActivity.intent.packageName);
        
        
        var intent = Ti.Android.createIntent({className: "com.test.classnameActivity", packageName: "com.test"});
        
        Ti.API.info("Class name: " + intent.getClassName());
        Ti.API.info("Class name: " + intent.className);
        
        Ti.API.info("Package name: " + intent.getPackageName());
        Ti.API.info("Package name: " + intent.packageName);
        
  11. Ashraf Abu 2016-05-25

    PR https://github.com/appcelerator/titanium_mobile/pull/8013 has been merged.
  12. Lokesh Choudhary 2016-07-08

    Verified the fix. The Ti.Android.currentActivity.intent.className & Ti.Android.currentActivity.intent.packageName is not undefined. Closing. Environment: Appc Studio : 4.7.0.201607070843 Ti SDK : 5.4.0.v20160705213725 Ti CLI : 5.0.9 Alloy : 1.9.1 MAC El Capitan : 10.11.5 Appc NPM : 4.2.8-1 Appc CLI : 5.4.0-29 Node: 4.4.4 Nexus 6 - Android 6.0.1

JSON Source