@@ -54,6 +54,9 @@ private RudderContext() {
5454 RudderContext (Application application , String anonymousId , String advertisingId ) {
5555 this .app = new RudderApp (application );
5656
57+ if (TextUtils .isEmpty (anonymousId )) {
58+ anonymousId = Utils .getDeviceId (application );
59+ }
5760 // get saved traits from prefs. if not present create new one and save
5861 RudderPreferenceManager preferenceManger = RudderPreferenceManager .getInstance (application );
5962 String traitsJson = preferenceManger .getTraits ();
@@ -62,17 +65,18 @@ private RudderContext() {
6265 RudderTraits traits = new RudderTraits (anonymousId );
6366 this .traits = Utils .convertToMap (new Gson ().toJson (traits ));
6467 this .persistTraits ();
68+ _anonymousId = anonymousId ;
6569 RudderLogger .logDebug ("New traits has been saved" );
6670 } else {
6771 this .traits = Utils .convertToMap (traitsJson );
72+ Object savedAnonymousId = this .traits .get ("anonymousId" );
73+ if (savedAnonymousId == null ) {
74+ _anonymousId = anonymousId ;
75+ } else {
76+ _anonymousId = savedAnonymousId .toString ();
77+ }
6878 RudderLogger .logDebug ("Using old traits from persistence" );
6979 }
70- Object savedAnonymousId = this .traits .get ("anonymousId" );
71- if (savedAnonymousId == null ) {
72- _anonymousId = Utils .getDeviceId (application );
73- } else {
74- _anonymousId = savedAnonymousId .toString ();
75- }
7680
7781 // get saved external Ids from prefs. if not present set it to null
7882 String externalIdsJson = preferenceManger .getExternalIds ();
0 commit comments