Closed ahasbini closed 6 years ago
@f2prateek sorry if it's a bad time, just wondering if if there's a solution for such an issue or if I'm doing anything wrong?
Have updated from 2.0.1 to 2.0.3. Still getting the same error.
I've logged the Bundle
during onSavedInstanceState
call and when it is coming in again in onCreate
once the Activity
is re-created. Realized that they contain the same data in both (Array of Items) however it seems that somewhere and somehow they are not being of the same type (Stack
) when Activity
is re-created. Instead it is being of ArrayList
type. And when the generated Injector is running it is directly casting the object to Stack
as in below:
public class MainActivity$$ExtraInjector {
public static void inject(Dart.Finder finder, MainActivity target, Object source) {
Object object;
object = finder.getExtra(source, "stateStack");
if (object != null) {
target.stateStack = (Stack<MainActivity.State>) object;
}
}
}
I've added the following to manually extract the Stack
object before calling Dart.inject()
instead of letting Dart to re-inject it:
// A work around to handle restoration with object being mutated for some reason
stateStack = new Stack<>();
if (savedInstanceState.containsKey("stateStack")) {
Logger.LogI(TAG, "restoreFromSavedState: found stateStack");
List<State> stateList = (List<State>) savedInstanceState.get("stateStack");
stateStack.addAll(stateList);
savedInstanceState.remove("stateStack");
}
Would be nice if when generating the Injector it could handle classes of Collection
or List
differently by creating a new instance of the object and then adding them all from the received Collection
/List
in the Bundle
. Although I do think that there might be something wrong from Android side that is causing this mutation.
Please feel free to close the issue as my problem has been solved with this workaround. Thanks!
Your issue is a bit complicated. What would really help us would be a sample or even better: a failing junit test added to the tests suite of dart. We are missing too many details to solve the issue just by reading the description.
Hi all.
I'm facing an issue with inject
java.util.Stack
objects usingDart.inject
. I'm using Dart in restoring thesavedInstanceState
of an activity. During my development, I often use Instant Run which automatically kills the app and send thesavedInstantState
upon callingonCreate
. I simply take the chance of speeding up my development by restoring the variables in the activity using Dart and being able to continue the flow of the application. One of the variables that is restored is of typeStack
. With Instant Run the object is being restored properly. However, when the application is long gone and terminated, and then it is restored from recent apps, the application crashes while Dart is injecting back the object.The following is the log detailing the scenario:
Appreciate if someone could help me with this, thanks.