New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Showing a badge throws IndexOutOfBoundsException if called from main Activity lifecycle methods #19
Labels
Comments
This seems to be the same problem for me too... please fix it... i can't able to load the badges when using at oncreate |
I have same problem how can i fix it???? |
not yet fixed ? |
same problem too. |
You can achieve the same goal of this lib using the new built-in bottomnav in Materiel components. |
still not fixed :/ |
Same problem too =( . Has anyone managed to find any contouring solution? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @armcha, really liking the library!
I set up my SpaceNavigationView in the onCreate of my Activity with the same setup shown in the readme and have added
bottomNav.onSaveInstanceState(outState);
in my onSaveInstanceState.Everything looks and works great in the launched activity, SpaceOnClickListener events are returning the correct name and index for my items. But if I try to call
spaceNavigationView.showBadgeAtIndex(0,5, ContextCompat.getColor(this, R.color.cyan));
in any of the main lifecycle methods in my Activity (bottom of onCreate, onResume, onPostResume, etc.) the SpaceNavigationView throws an IndexOutOfBoundsException:
Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255) at java.util.ArrayList.get(ArrayList.java:308) at com.luseen.spacenavigation.SpaceNavigationView.showBadgeAtIndex(SpaceNavigationView.java:822) at com.proto.tangible.tagalong.ExploreActivity$override.onResume(ExploreActivity.java:193) at com.proto.tangible.tagalong.ExploreActivity$override.access$dispatch(ExploreActivity.java) at com.proto.tangible.tagalong.ExploreActivity.onResume(ExploreActivity.java:0) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1326) at android.app.Activity.performResume(Activity.java:6323) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3311) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3359) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2549) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4398) at android.app.ActivityThread.access$1000(ActivityThread.java:150) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1400) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:168) at android.app.ActivityThread.main(ActivityThread.java:5845) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
However, calling the same line some time after the Activity loads (in response to a manual click event or async task with Thread.sleep(400) works just fine for me!
Looking at the library source it seems like the SpaceNavigationView needs to have been laid out before its possible to show badges for your SpaceItems. In most situations the badge quantity to display is calculated almost instantly, so waiting for the draw is a little cumbersome
The text was updated successfully, but these errors were encountered: