question

coachup avatar image
coachup asked

Error retrieving variations causes Android views to disappear

Hello, I am encountering an unusual error when integrating the Amazon Insights A/B testing code with my Android app. Approximately 8 times out of 10, the app works as intended - it gets the variation and handles the contents of it correctly. However, sometimes I encounter this error: 11-03 10:47:57.988: V/AmazonInsightsSDK(7765): Firing Session Event: _session.start 11-03 10:47:57.988: I/AmazonInsightsSDK(7765): Amazon Insights SDK(2.1.26.0) initialization successfully completed 11-03 10:47:57.998: I/AmazonInsightsSDK(7765): Event: '_sess...' recorded to local filestore 11-03 10:48:05.777: I/AmazonInsightsSDK(7765): Attempting to retrieve variation(s) for project(s):'ESF' 11-03 10:48:05.817: I/AmazonInsightsSDK(7765): Event: 'Searc...' recorded to local filestore 11-03 10:48:05.827: I/AmazonInsightsSDK(7765): Resolved expired variation: 'TEST' for project: 'ESF' from cache 11-03 10:48:06.257: I/AmazonInsightsSDK(7765): Event: '_http...' recorded to local filestore 11-03 10:48:06.267: I/AmazonInsightsSDK(7765): Resolved variation: 'Test' for project: 'ESF' from server 11-03 10:48:06.277: E/AmazonInsightsSDK(7765): An unexpected error occurred. Retrieval of variations could not be completed Whenever I encounter this error, all the views on this Fragment and its parent Activity become invisible. Navigating to new or existing Fragments within this activity, which do not use Amazon Insights variations, also cause the presented Fragment to disappear. It appears that the activity's views outside of the Fragment view still work - the side drawer works, and hitting a button in the Action Bar does correctly toast. Starting a different activity also works as intended. When viewing the getSupportFragmentManager() for the activity, it appears to be the same in this error situation as it does in other error situations, e.g. correctly showing the active fragment(s) on mActive. Fragment transactions are handled correctly, as the title and Action Bar are updated as I move from fragment to fragment - the main Fragment view just continues to be a white screen. My callback implementation is: private InsightsCallback callback = new InsightsCallback () { @Override public void onComplete(VariationSet variations) { experimentVariation = variations.getVariation(ExperimentManager.ESF_EXPERIMENT_PROJECT); if (experimentVariation != null) { extraView.setText(experimentVariation.getVariableAsBoolean("showESF", false) ? "Wow!" : "Great!"); } } @Override public void onError(final InsightsError error) { super.onError(error); extraView.setText("Great!") } }; The app has worked successfully in the field for over a year already, so I am certain the error is coming from the Amazon Insights integration.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

coachup avatar image
coachup answered
It appears that running UI code in the callback directly is causing the error. Forcing that code to run on the UI thread fixes the problem. I'm actually more confused as to why the code worked correctly most of the time as it seems like this should always fail.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.