Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17084] Android: ActionBar: setNavigationMode() crashes the app

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionWon't Fix
Resolution Date2014-07-03T19:25:16.000+0000
Affected Version/sRelease 3.3.0
Fix Version/sRelease 3.4.0
ComponentsAndroid
Labelsqe-3.3.0
ReporterParas Mishra
AssigneeSunila
Created2014-06-06T12:21:44.000+0000
Updated2017-03-22T23:00:53.000+0000

Description

Android: ActionBar: setNavigationMode() crashes the app This is regression.It works fine with 3.2.3.GA SDK Steps to reproduce: 1. Run the app attached app TIMOB-13135.zip 2. Tap on button "open childWin(same activity)". 3. Tap on button "show the tabs". Expected: Tabs should be shown Actual: App crashes, logs are as follows
[WARN] :   dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41e88ba8)
[ERROR] :  TiApplication: (main) [246940,246940] Sending event: exception on thread: main msg:java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState; Titanium 3.3.0,2014/06/05 15:06,708f5ce
[ERROR] :  TiApplication: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
[ERROR] :  TiApplication: 	at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1354)
[ERROR] :  TiApplication: 	at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1372)
[ERROR] :  TiApplication: 	at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
[ERROR] :  TiApplication: 	at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
[ERROR] :  TiApplication: 	at android.support.v7.app.ActionBarImplICS.commitActiveTransaction(ActionBarImplICS.java:378)
[ERROR] :  TiApplication: 	at android.support.v7.app.ActionBarImplICS$TabWrapper.onTabSelected(ActionBarImplICS.java:559)
[ERROR] :  TiApplication: 	at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:577)
[ERROR] :  TiApplication: 	at com.android.internal.app.ActionBarImpl.setSelectedNavigationItem(ActionBarImpl.java:363)
[ERROR] :  TiApplication: 	at com.android.internal.app.ActionBarImpl.setNavigationMode(ActionBarImpl.java:1196)
[ERROR] :  TiApplication: 	at android.support.v7.app.ActionBarImplICS.setNavigationMode(ActionBarImplICS.java:229)
[ERROR] :  TiApplication: 	at android.support.v7.app.ActionBarImplJB.setNavigationMode(ActionBarImplJB.java:20)
[ERROR] :  TiApplication: 	at org.appcelerator.titanium.proxy.ActionBarProxy.handlesetNavigationMode(ActionBarProxy.java:321)
[ERROR] :  TiApplication: 	at org.appcelerator.titanium.proxy.ActionBarProxy.handleMessage(ActionBarProxy.java:352)
[ERROR] :  TiApplication: 	at android.os.Handler.dispatchMessage(Handler.java:98)
[ERROR] :  TiApplication: 	at android.os.Looper.loop(Looper.java:136)
[ERROR] :  TiApplication: 	at android.app.ActivityThread.main(ActivityThread.java:5017)
[ERROR] :  TiApplication: 	at java.lang.reflect.Method.invokeNative(Native Method)
[ERROR] :  TiApplication: 	at java.lang.reflect.Method.invoke(Method.java:515)
[ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
[ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
[ERROR] :  TiApplication: 	at dalvik.system.NativeStart.main(Native Method)

Attachments

FileDateSize
TIMOB-13135.zip2014-06-06T12:21:45.000+00006669486

Comments

  1. Hieu Pham 2014-06-09

    Here's the test case converted to native Titanium:
       var actionBar = null;
        
       function openChild() {
           var win = Ti.UI.createWindow({backgroundColor: 'white'});
           
           var button1 = Ti.UI.createButton({top: 100, title:'hide the tabs'});
           var button2 = Ti.UI.createButton({top: 200, title:'show the tabs'});
           var button3 = Ti.UI.createButton({top: 300, title:'getNavigation mode'});
           button1.addEventListener('click', setStandard);
           button2.addEventListener('click', setTabs);
           button3.addEventListener('click', getNavMode);
           
           win.add(button1);
           win.add(button2);
           win.add(button3);
           
            
           if (Ti.Platform.name === 'android') {
               if (actionBar) {
                   //made sure both property and setter work :)
                   //actionBar.setNavigationMode(0);
                   actionBar.navigationMode = 0;
               }
               win.open();
           }
       }
       
       function setStandard() {
           if (actionBar) {
               actionBar.setNavigationMode(0);
           }
       }
        
       function setTabs() {
           if (actionBar) {
               actionBar.setNavigationMode(2);
           }   
       }
        
       function getNavMode() {
           if (actionBar) {
               alert('The navigation mode is: ' + actionBar.getNavigationMode());
           }
       }
       
       var myTabs = Ti.UI.createTabGroup({backgroundColor: 'white'});
       var win1 = Ti.UI.createWindow({title: "Tab 1"});
       var button1 = Ti.UI.createButton({title: "open childWin (same activity)", top: 70});
       var button2 = Ti.UI.createButton({title: "getNavigationMode()", top: 200});
       button1.addEventListener('click', openChild);
       button2.addEventListener('click', getNavMode);
       win1.add(button1);
       win1.add(button2);
       var tab1 = Ti.UI.createTab({window: win1});
       
       myTabs.addEventListener('open', function() {
           if (Ti.Platform.name === 'android') {
               var tabGroupAct = myTabs.getActivity();
               actionBar = tabGroupAct.actionBar;
               if (actionBar){
                   actionBar.title = "Rock n' Roll";
               }
           }
       });
       myTabs.addTab(tab1);
       myTabs.open();
       
  2. Eric Merriman 2014-07-01

    Some additional information: This error will occur with what we would in the past call a "heavyweight" window. In the past, heavyweight and lightweight windows could both be created - this was based on the specified options during window creation. A tiapp.xml setting was added: "ti.android.useLegacyWindow" which initially had a default of "true" which allows the use of either window type. The default for this setting was then set to "false", which means all windows would use the new architecture as described in TIMOB-13796. As of 3.3.0 this option is no longer available, and ALL projects will use the new architecture. Since this error occurs on what we used to call a "heavyweight" window, and this is now the only option, this issue will always occur with 3.3.0 or greater, but will depend on both the tiapp.xml setting and the method window creation in 3.2.3.
  3. Sunila 2014-07-02

    With heavyweight window, each window has it's own activity associated with it. When 'openChild' is called, a new activity is launched and the old activity is stopped by the Android OS. This will result in OS calling onSaveInstanceState on the previous activity before stopping the activity. When 'show the tabs' is clicked, it is trying to modify the state of the fragment which was already saved and stopped. Since activity is already stopped, modified state will be lost if the activity is destroyed and hence Android throws this exception. Changing the state in the same activity (setNavigationMode) works without any issue. I don't think this is a bug.
  4. Hieu Pham 2014-07-03

    A simple workaround is to replace LW window with a view. You can do this by replacing the openChild() function in the above test case with:
       function openChild() {
           var view = Ti.UI.createView({backgroundColor: 'white'});
            
           var button1 = Ti.UI.createButton({top: 100, title:'hide the tabs'});
           var button2 = Ti.UI.createButton({top: 200, title:'show the tabs'});
           var button3 = Ti.UI.createButton({top: 300, title:'getNavigation mode'});
           button1.addEventListener('click', setStandard);
           button2.addEventListener('click', setTabs);
           button3.addEventListener('click', getNavMode);
            
           view.add(button1);
           view.add(button2);
           view.add(button3);
            
             
           if (Ti.Platform.name === 'android') {
               if (actionBar) {
                   //made sure both property and setter work :)
                   //actionBar.setNavigationMode(0);
                   actionBar.navigationMode = 0;
               }
           }
           win1.add(view);
       }
       
  5. Eric Merriman 2014-07-03

  6. Sai Suman Mallela 2014-07-24

    What version of Release 3.4.0 is this bug fixed ?? I installed the following continuous build : FRI JUL 18, 2014 2:57:13 PM version: 3.4.0 git hash: 58198c641d77e17d156431666e80bae732b5c130 Still am getting the above error.
  7. Lee Morris 2017-03-22

    Closing ticket as "Won't Fix".

JSON Source