Gabriel Feo
07/21/2020, 2:02 AMView.generateViewId()
here with programatically created Views. It only outputs sequential IDs starting with 1
, and onRestoreInstanceState
on these Views isn't called at all upon restore. Any ideas?satyan
07/21/2020, 6:29 AMgenerateViewId
will generate ids which do not collide with generated ID values so I guess sequential IDs starting with 1
don’t collide 🤷 .
As for onRestoreInstanceState
, as I read it, if nothing is saved by onSavedInstance
state, it won’t be calledgenerateViewId
:
public static int generateViewId() {
for (;;) {
final int result = sNextGeneratedId.get();
// aapt-generated IDs have the high byte nonzero; clamp to the range under that.
int newValue = result + 1;
if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
if (sNextGeneratedId.compareAndSet(result, newValue)) {
return result;
}
}
}
sNextGeneratedId
being initialised with
new AtomicInteger(1)
Gabriel Feo
07/21/2020, 9:52 PMActivity.onCreate
, and generating its ID each time, so there was no guarantee that the ID in the saved state would be a match