@@ -480,7 +480,14 @@ protected Void doInBackground(Void... params) {
480480 });
481481 }
482482
483- private void sendRequests () {
483+
484+ private static class RequestsWithEncoding {
485+ List <Map <String , Object >> unsentRequests ;
486+ List <Map <String , Object >> requestsToSend ;
487+ String jsonEncodedString ;
488+ }
489+
490+ private RequestsWithEncoding getRequestsWithEncodedString () {
484491 List <Map <String , Object >> unsentRequests = new ArrayList <>();
485492 List <Map <String , Object >> requestsToSend ;
486493 // Check if we have localErrors, if yes then we will send only errors to the server.
@@ -496,6 +503,23 @@ private void sendRequests() {
496503 requestsToSend = removeIrrelevantBackgroundStartRequests (unsentRequests );
497504 }
498505
506+ String jsonEncodedRequestsToSend = jsonEncodeUnsentRequests (unsentRequests );
507+
508+ RequestsWithEncoding requestsWithEncoding = new RequestsWithEncoding ();
509+ requestsWithEncoding .unsentRequests = unsentRequests ;
510+ requestsWithEncoding .requestsToSend = requestsToSend ;
511+ requestsWithEncoding .jsonEncodedString = jsonEncodedRequestsToSend ;
512+
513+ return requestsWithEncoding ;
514+ }
515+
516+ private void sendRequests () {
517+ RequestsWithEncoding requestsWithEncoding = getRequestsWithEncodedString ();
518+
519+ List <Map <String , Object >> unsentRequests = requestsWithEncoding .unsentRequests ;
520+ List <Map <String , Object >> requestsToSend = requestsWithEncoding .requestsToSend ;
521+ String jsonEncodedString = requestsWithEncoding .jsonEncodedString ;
522+
499523 if (requestsToSend .isEmpty ()) {
500524 return ;
501525 }
@@ -504,7 +528,7 @@ private void sendRequests() {
504528 if (!Request .attachApiKeys (multiRequestArgs )) {
505529 return ;
506530 }
507- multiRequestArgs .put (Constants .Params .DATA , jsonEncodeUnsentRequests ( requestsToSend ) );
531+ multiRequestArgs .put (Constants .Params .DATA , jsonEncodedString );
508532 multiRequestArgs .put (Constants .Params .SDK_VERSION , Constants .LEANPLUM_VERSION );
509533 multiRequestArgs .put (Constants .Params .ACTION , Constants .Methods .MULTI );
510534 multiRequestArgs .put (Constants .Params .TIME , Double .toString (new Date ().getTime () / 1000.0 ));
0 commit comments