Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11824] Android: Opening alert() from action bar "home" icon click handler causes crash

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-04-10T22:54:02.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 3.1.0, 2012 Sprint 26 Core, 2012 Sprint 26, 2013 Sprint 06 Core, 2013 Sprint 06
ComponentsAndroid
Labelsqe-closed-3.1.0, qe-testadded
ReporterArthur Evans
AssigneeAllen Yeung
Created2012-11-19T20:47:51.000+0000
Updated2013-10-03T07:10:54.000+0000

Description

When testing TIMOB-11642, I tried the following code:
win1.addEventListener("open", function(evt) {
    var actionBar = win1.activity.actionBar;
    Ti.API.info("In evt. listener, actionBar is: " + actionBar);
    actionBar.title = "Title Demo";
    actionBar.onHomeIconItemSelected = function() {
        alert("Home clicked!");
    }
});
As reported by @igorsantos07, I got a crash on this. If I replace the alert with a Ti.API.info call, all goes well. Weird.

Comments

  1. Allen Yeung 2012-12-06

    PR: https://github.com/appcelerator/titanium_mobile/pull/3545 Full test case:
       var win = Ti.UI.createWindow({
           fullscreen : true
       });
        
       win.addEventListener('open', function(){
           var actionBar = win.activity.actionBar;
           actionBar.onHomeIconItemSelected = function() {
               alert('home clicked');
           }
       });
        
       win.open();
       
  2. Paras Mishra 2013-02-26

    As soon as app is executed. It crashes. Tested on: Google nexus, android verison: 4.1 SDK version: 3.1.0.v20130225195538 CLI version : 3.0.24 OS : MAC OSX 10.7.5 XCode : 4.5.1 Studio : 3.0.2.201302041757 Expected : Opening alert() from action bar, app should not crash. Actual: Application crashes.
  3. Allen Yeung 2013-03-19

    Resolving... I tried three devices and it worked fine. Galaxy Nexus (4.1), Nexus 4 (4.2), and Galaxy tab (3.2). If you see this issue, please also attach logs.
  4. Paras Mishra 2013-04-10

    App still crashes as soon as it executes. Tested on: Device : Google Nexus 7, Android Version: 4.1 SDK: 3.1.0.v20130409124549 CLI version : 3.1.0-cr OS : MAC OSX 10.7.5 Appcelerator Studio, build: 3.1.0.201304052347 XCode : 4.5.1 Here's the log 04-10 15:09:57.214: W/dalvikvm(25018): threadid=1: thread exiting with uncaught exception (group=0x411bd300) 04-10 15:09:57.214: E/TiApplication(25018): (main) [45,45] Sending event: exception on thread: main msg:java.lang.NullPointerException; Titanium 3.1.0,2013/04/09 12:46,485b313 04-10 15:09:57.214: E/TiApplication(25018): java.lang.NullPointerException 04-10 15:09:57.214: E/TiApplication(25018): at org.appcelerator.titanium.proxy.ActionBarProxy.handleMessage(ActionBarProxy.java:222) 04-10 15:09:57.214: E/TiApplication(25018): at android.os.Handler.dispatchMessage(Handler.java:95) 04-10 15:09:57.214: E/TiApplication(25018): at android.os.Looper.loop(Looper.java:137) 04-10 15:09:57.214: E/TiApplication(25018): at android.app.ActivityThread.main(ActivityThread.java:4745) 04-10 15:09:57.214: E/TiApplication(25018): at java.lang.reflect.Method.invokeNative(Native Method) 04-10 15:09:57.214: E/TiApplication(25018): at java.lang.reflect.Method.invoke(Method.java:511) 04-10 15:09:57.214: E/TiApplication(25018): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 04-10 15:09:57.214: E/TiApplication(25018): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 04-10 15:09:57.214: E/TiApplication(25018): at dalvik.system.NativeStart.main(Native Method) 04-10 15:09:57.254: E/AndroidRuntime(25018): FATAL EXCEPTION: main 04-10 15:09:57.254: E/AndroidRuntime(25018): java.lang.NullPointerException 04-10 15:09:57.254: E/AndroidRuntime(25018): at org.appcelerator.titanium.proxy.ActionBarProxy.handleMessage(ActionBarProxy.java:222) 04-10 15:09:57.254: E/AndroidRuntime(25018): at android.os.Handler.dispatchMessage(Handler.java:95) 04-10 15:09:57.254: E/AndroidRuntime(25018): at android.os.Looper.loop(Looper.java:137) 04-10 15:09:57.254: E/AndroidRuntime(25018): at android.app.ActivityThread.main(ActivityThread.java:4745) 04-10 15:09:57.254: E/AndroidRuntime(25018): at java.lang.reflect.Method.invokeNative(Native Method) 04-10 15:09:57.254: E/AndroidRuntime(25018): at java.lang.reflect.Method.invoke(Method.java:511) 04-10 15:09:57.254: E/AndroidRuntime(25018): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 04-10 15:09:57.254: E/AndroidRuntime(25018): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 04-10 15:09:57.254: E/AndroidRuntime(25018): at dalvik.system.NativeStart.main(Native Method) 04-10 15:09:57.254: W/ActivityManager(348): Force finishing activity com.APPLE/org.appcelerator.titanium.TiActivity 04-10 15:09:57.284: W/ActivityManager(348): Force finishing activity com.APPLE/.Test01Activity 04-10 15:09:57.784: W/ActivityManager(348): Activity pause timeout for ActivityRecord{41e30a68 com.APPLE/org.appcelerator.titanium.TiActivity} 04-10 15:10:00.104: I/Process(25018): Sending signal. PID: 25018 SIG: 9
  5. Allen Yeung 2013-04-10

    This error only occurs if you didn't specify your app to be API 11 and above. Please add this to your tiapp.xml:
           <android xmlns:android="http://schemas.android.com/apk/res/android">
               <manifest>
                   <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="11"/>
               </manifest>
           </android>
       
    Please see http://docs.appcelerator.com/titanium/latest/#!/guide/Android_Action_Bar for more info.
  6. Anshu Mittal 2013-04-11

    Tested with: SDK: 3.1.0.v20130409124549 Studio:3.1.0.201304011603 Device: Nexus 7(v 4.1) OS: OSX 10.7.5 Works as expected after specifying android:targetSdkVersion="11" along with the specified code.

JSON Source