I initialize one variable in an onUpdate() method and after that I call onReceive() function which runs fine but cannot access varible set in onUpdate() method. Why is that
for a AppWidgetReceiver , first onReceive() will be called and then based on the Action received, it will call onUpdate(...) method. so here you are initializing state in onUpdate() which will be called after onReceive(), thus state is null in onReceive().