I am using this code in my Android app (RoboGuice library):
@Singleton
public class UserSessionProvider {
private User user;
@Inject
private Injector injector;
public synchronized User createSession() {
this.user = injector.getInstance(User.class);
return this.user;
}
public synchronized User getUser() {
return user;
}
public synchronized void destroySession() {
this.user = null;
}
public synchronized Boolean isSessionAlive() {
return getUser() != null;
}
}
Sometimes build gets bugged up, and application fails to inject instance of injector in this provider. When I clean app and rebuild it then it again works ok (for some time). I am using Gradle build chain and Android studio. Does anyone know how can I stop this from happening?