Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

confused about referencing Activity proxy

$
0
0

Hello,

I'm currently messing around with Android Activities and I'm a little bit confused about the Titanium Proxy of the Android Activity. Titanium has an Android API to access an Activity. So, what I did is, I created a new default Alloy project and recognized the following within index.js:

Ti.Android.currentActivity returns [object Activity]

Ti.Android.getCurrentActivity() raises a runtime error:

Uncaught TypeError: Object #<Android> has no method 'getCurrentActivity'
According to the Documentation both statements should return the same reference to my Activity, right?

Next, I tried this:

Ti.API.info($.index.activity);  //returns  [object Object]
Ti.API.info($.index.getActivity());   //returns  [object Object]
 
$.index.addEventListener('open', function(){
    Ti.API.info($.index.activity);   //returns  [object Activity]
    Ti.API.info($.index.getActivity());   //returns  [object Activity]
});
 
$.index.open();
I don't know what this object is, that I get at the first statements, but as you can see, the actual Activity can only be referenced after the according heavyweight window is opened. I don't know if this is just not well documented but it seems that this behavior is similar to the Ti.UI.TabGroup.

My last test was making my index window heavyweight by adding navBarHidden: true and trying this:

$.index.addEventListener('open', function(){
    Ti.API.info($.index.activity === Ti.Android.currentActivity); // returns false
});
So, why is this false?

I'm afraid, Ti.Android.currentActivity is referencing the Ti Root Activity (TiActivity) instead of the "index" Activity (MyTestActivity).

08-30 17:37:16.642: I/ActivityManager(441): START u0 {cmp=com.test.activity/org.appcelerator.titanium.TiActivity (has extras)} from pid 18044
08-30 17:37:16.672: I/ActivityManager(441): Displayed com.test.activity/.MyTestActivity: +996ms
Can anybody put this in perspective and explain what happens? Thanks a lot!

Manuel

SDK Titanium SDK version: 3.1.2, Alloy 1.2.1, Mac OS X 10.8.4, Test device: Nexus 7, Android 4.3


Viewing all articles
Browse latest Browse all 8068

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>