stormpath / stormpath-sdk-android

Android library for Stormpath
http://www.stormpath.com
Apache License 2.0
18 stars 15 forks source link

Initializing Stormpath sdk after already initializing once causes fatal crash #29

Open LithiumSheep opened 7 years ago

LithiumSheep commented 7 years ago

This is generally only an issue with incremental builds with AS instant run. There is the helper method Stormpath.isInitialized() but a better solution may be to initialize Stormpath in the project's Application subclass.

Here is the stracktrace when Stormpath is initialized after already being initialized: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.lithium.authproject, PID: 28651 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lithium.authproject/com.lithium.authproject.MainActivity}: java.lang.IllegalStateException: You may only initialize Stormpath once! at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4519) at android.app.ActivityThread.-wrap19(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1483) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) Caused by: java.lang.IllegalStateException: You may only initialize Stormpath once! at com.stormpath.sdk.Stormpath.init(Stormpath.java:48) at com.stormpath.sdk.Stormpath.init(Stormpath.java:33) at com.lithium.authproject.MainActivity$override.initStormpath(MainActivity.java:47) at com.lithium.authproject.MainActivity$override.onCreate(MainActivity.java:35) at com.lithium.authproject.MainActivity$override.access$dispatch(MainActivity.java) at com.lithium.authproject.MainActivity.onCreate(MainActivity.java:0) at android.app.Activity.performCreate(Activity.java:6679) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4519)  at android.app.ActivityThread.-wrap19(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1483)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6119)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)