My app gets crashed frequently when it goes from background to foreground. Scenerio: Suppose iam playing any games and my app is in recent list and after playing,if i select
This can also happen in this edge case:
If you create a custom view programmatically inside the constructor of another parent view that has the AttributeSet parameter:
public ToggleButtonDescriptive(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.toggleButton = new SquareToggleButton(ctx, attributeSet);
}
DO NOT pass the AttributeSet to that child View:
toggleButton = new SquareToggleButton(ctx, attributeSet);
As passing the AttributeSet causes the child view to have the same id as the parent and thus Android tries to restore the parents SavedState to that child view or vice versa. Instead omit the AttributeSet parameter altogether, like this:
toggleButton = new SquareToggleButton(ctx);