phonegap-android-actionbarsherlock-tabbar-plugin icon indicating copy to clipboard operation
phonegap-android-actionbarsherlock-tabbar-plugin copied to clipboard

Screen Rotate Bug

Open digitalguides opened this issue 12 years ago • 6 comments

Great plugin. However, when i rotate the screen it causes the App to stop, and I think something else is causing a crash but not tracked that down yet.

digitalguides avatar Feb 08 '13 09:02 digitalguides

What's the exception trace in LogCat?

AndiDog avatar Feb 10 '13 08:02 AndiDog

Which exception do you get in LogCat?

AndiDog avatar Feb 10 '13 17:02 AndiDog

02-20 08:24:48.248: D/dalvikvm(2056): Late-enabling CheckJNI 02-20 08:24:48.893: I/CordovaLog(2056): Changing log level to DEBUG(3) 02-20 08:24:48.893: I/CordovaLog(2056): Found preference for useBrowserHistory=false 02-20 08:24:48.893: D/CordovaLog(2056): Found preference for useBrowserHistory=false 02-20 08:24:48.893: I/CordovaLog(2056): Found preference for exit-on-suspend=false 02-20 08:24:48.893: D/CordovaLog(2056): Found preference for exit-on-suspend=false 02-20 08:24:48.893: W/CordovaWebView(2056): useBrowserHistory=false is deprecated as of Cordova 2.2.0 and will be removed six months after the 2.2.0 release. Please use the browser history and use history.back(). 02-20 08:24:48.924: D/JsMessageQueue(2056): Set native->JS mode to 2 02-20 08:24:48.994: D/DroidGap(2056): DroidGap.init() 02-20 08:24:49.275: D/dalvikvm(2056): GC_CONCURRENT freed 175K, 4% free 8260K/8519K, paused 85ms+2ms, total 117ms 02-20 08:24:49.420: D/CordovaWebView(2056): DroidGap.loadUrl(file:///android_asset/www/index.html, 25000) 02-20 08:24:49.420: D/DroidGap(2056): onMessage(splashscreen,show) 02-20 08:24:49.420: D/CordovaWebView(2056): >>> loadUrl(file:///android_asset/www/index.html) 02-20 08:24:49.420: D/PluginManager(2056): init() 02-20 08:24:49.459: D/CordovaWebView(2056): >>> loadUrlNow() 02-20 08:24:49.459: D/DroidGap(2056): Resuming the App 02-20 08:24:49.600: D/libEGL(2056): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so 02-20 08:24:49.615: D/libEGL(2056): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so 02-20 08:24:49.631: D/libEGL(2056): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so 02-20 08:24:49.830: D/OpenGLRenderer(2056): Enabling debug mode 0 02-20 08:24:49.857: D/SoftKeyboardDetect(2056): Ignore this event 02-20 08:24:50.197: D/DroidGap(2056): onMessage(onCreateOptionsMenu,com.android.internal.view.menu.MenuBuilder@413d58e8) 02-20 08:24:50.197: D/DroidGap(2056): onMessage(onPrepareOptionsMenu,com.android.internal.view.menu.MenuBuilder@413d58e8) 02-20 08:24:50.264: D/DroidGap(2056): onMessage(onPageStarted,file:///android_asset/www/index.html) 02-20 08:24:50.498: D/SoftKeyboardDetect(2056): Ignore this event 02-20 08:24:51.197: D/Cordova(2056): onPageFinished(file:///android_asset/www/index.html) 02-20 08:24:51.197: D/DroidGap(2056): onMessage(onNativeReady,null) 02-20 08:24:51.201: D/DroidGap(2056): onMessage(onPageFinished,file:///android_asset/www/index.html) 02-20 08:24:51.225: E/SQLiteLog(2056): (14) cannot open file at line 30174 of [00bb9c9ce4] 02-20 08:24:51.225: E/SQLiteLog(2056): (14) os_unix.c:30174: (2) open(/CachedGeoposition.db) - 02-20 08:24:51.225: D/WebKit(2056): ERROR: 02-20 08:24:51.225: D/WebKit(2056): SQLite database failed to load from /CachedGeoposition.db 02-20 08:24:51.225: D/WebKit(2056): Cause - unable to open database file 02-20 08:24:51.225: D/WebKit(2056): external/webkit/Source/WebCore/platform/sql/SQLiteDatabase.cpp(71) : bool WebCore::SQLiteDatabase::open(const WTF::String&, bool) 02-20 08:24:51.322: D/CordovaNetworkManager(2056): Connection Type: wifi 02-20 08:24:51.322: D/DroidGap(2056): onMessage(networkconnection,wifi) 02-20 08:24:51.330: D/CordovaNetworkManager(2056): Connection Type: wifi 02-20 08:24:51.354: D/DroidGap(2056): onMessage(spinner,stop) 02-20 08:24:51.357: D/DroidGap(2056): onMessage(splashscreen,hide) 02-20 08:24:51.412: D/TilesManager(2056): new EGLContext from framework: 4be389d8 02-20 08:24:51.412: D/GLWebViewState(2056): Reinit shader 02-20 08:24:51.416: D/GLWebViewState(2056): Reinit transferQueue 02-20 08:24:51.463: D/ActionBarSherlockTabBarPlugin(2056): Tab tab-travel selected 02-20 08:24:53.209: D/DroidGap(2056): onMessage(spinner,stop) 02-20 08:25:05.346: D/ActionBarSherlockTabBarPlugin(2056): Tab tab-travel unselected 02-20 08:25:05.354: D/ActionBarSherlockTabBarPlugin(2056): Tab tab-rewards selected 02-20 08:25:06.572: D/DroidGap(2056): Paused the application! 02-20 08:25:06.572: D/CordovaWebView(2056): Handle the pause 02-20 08:25:06.721: W/IInputConnectionWrapper(2056): showStatusIcon on inactive InputConnection 02-20 08:25:07.393: D/DroidGap(2056): onDestroy() 02-20 08:25:07.397: D/CordovaWebView(2056): >>> loadUrlNow() 02-20 08:25:07.842: D/DroidGap(2056): DroidGap.onCreate() 02-20 08:25:07.846: D/AndroidRuntime(2056): Shutting down VM 02-20 08:25:07.846: W/dalvikvm(2056): threadid=1: thread exiting with uncaught exception (group=0x40bf7300) 02-20 08:25:07.881: E/AndroidRuntime(2056): FATAL EXCEPTION: main 02-20 08:25:07.881: E/AndroidRuntime(2056): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.phonegapandroidtest/com.example.phonegapandroidtest.MainActivity}: java.lang.IllegalStateException: May only set ActionBarSherlock instance of tab bar once 02-20 08:25:07.881: E/AndroidRuntime(2056): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) 02-20 08:25:07.881: E/AndroidRuntime(2056): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 02-20 08:25:07.881: E/AndroidRuntime(2056): at android.app.ActivityThread.access$600(ActivityThread.java:130) 02-20 08:25:07.881: E/AndroidRuntime(2056): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 02-20 08:25:07.881: E/AndroidRuntime(2056): at android.os.Handler.dispatchMessage(Handler.java:99) 02-20 08:25:07.881: E/AndroidRuntime(2056): at android.os.Looper.loop(Looper.java:137) 02-20 08:25:07.881: E/AndroidRuntime(2056): at android.app.ActivityThread.main(ActivityThread.java:4745) 02-20 08:25:07.881: E/AndroidRuntime(2056): at java.lang.reflect.Method.invokeNative(Native Method) 02-20 08:25:07.881: E/AndroidRuntime(2056): at java.lang.reflect.Method.invoke(Method.java:511) 02-20 08:25:07.881: E/AndroidRuntime(2056): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 02-20 08:25:07.881: E/AndroidRuntime(2056): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 02-20 08:25:07.881: E/AndroidRuntime(2056): at dalvik.system.NativeStart.main(Native Method) 02-20 08:25:07.881: E/AndroidRuntime(2056): Caused by: java.lang.IllegalStateException: May only set ActionBarSherlock instance of tab bar once 02-20 08:25:07.881: E/AndroidRuntime(2056): at de.andidog.phonegapplugins.ActionBarSherlockTabBarPlugin.setSherlock(ActionBarSherlockTabBarPlugin.java:226) 02-20 08:25:07.881: E/AndroidRuntime(2056): at com.example.phonegapandroidtest.MainActivity.createTabs(MainActivity.java:35) 02-20 08:25:07.881: E/AndroidRuntime(2056): at com.example.phonegapandroidtest.MainActivity.access$0(MainActivity.java:33) 02-20 08:25:07.881: E/AndroidRuntime(2056): at com.example.phonegapandroidtest.MainActivity$1.run(MainActivity.java:55) 02-20 08:25:07.881: E/AndroidRuntime(2056): at android.app.Activity.runOnUiThread(Activity.java:4591) 02-20 08:25:07.881: E/AndroidRuntime(2056): at com.example.phonegapandroidtest.MainActivity.onActionBarSherlockTabBarPluginInitialized(MainActivity.java:51) 02-20 08:25:07.881: E/AndroidRuntime(2056): at de.andidog.phonegapplugins.ActionBarSherlockTabBarPlugin.setOnInitListener(ActionBarSherlockTabBarPlugin.java:245) 02-20 08:25:07.881: E/AndroidRuntime(2056): at com.example.phonegapandroidtest.MainActivity.onCreate(MainActivity.java:25) 02-20 08:25:07.881: E/AndroidRuntime(2056): at android.app.Activity.performCreate(Activity.java:5008) 02-20 08:25:07.881: E/AndroidRuntime(2056): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 02-20 08:25:07.881: E/AndroidRuntime(2056): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 02-20 08:25:07.881: E/AndroidRuntime(2056): ... 11 more 02-20 08:25:07.986: D/dalvikvm(2056): GC_CONCURRENT freed 347K, 6% free 8396K/8839K, paused 23ms+2ms, total 128ms 02-20 08:25:15.873: I/Process(2056): Sending signal. PID: 2056 SIG: 9

digitalguides avatar Feb 20 '13 08:02 digitalguides

Above is full LogCat when i run the Test App (MainActivity)

digitalguides avatar Feb 20 '13 08:02 digitalguides

Please try with the latest commit.

AndiDog avatar Mar 24 '13 18:03 AndiDog

The problem is that deviceready from Cordova seems to get called again on rotation. A new instance of the tab bar plugin gets created, one where the sherlock variables has not been assigned to. A potential one-line fix to ActionBarSherlockTabBarPlugin: Change protected ActionBarSherlock sherlock; to protected static ActionBarSherlock sherlock;

You may also need to ensure duplicate tabs don't get added on rotate if making the above change.

jameswomack avatar Oct 17 '13 20:10 jameswomack