Skip to content

Commit

Permalink
Merge pull request #23 from avohq/fix-start-race-condition
Browse files Browse the repository at this point in the history
Fix start race condition
  • Loading branch information
bjornj12 authored Jan 14, 2022
2 parents 3393453 + 5b8bb73 commit b9d0a57
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.2

Fixed a race condition that caused some of the early events in the app lifecycle to be not reported.

## 2.0.1

Disabled batching in the dev mode by default.
Expand Down
4 changes: 3 additions & 1 deletion avoinspector/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/build
sentry.properties
sentry.properties
/.idea
local.properties
6 changes: 3 additions & 3 deletions avoinspector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 14
targetSdkVersion 30
versionCode 4
versionName "2.0.1"
versionName "2.0.2"

testInstrumentationRunner "AndroidJUnit4"
consumerProguardFiles 'consumer-rules.pro'
Expand Down Expand Up @@ -65,15 +65,15 @@ afterEvaluate {

groupId = 'com.github.avohq'
artifactId = 'prod'
version = '2.0.1'
version = '2.0.2'
}

development(MavenPublication) {
from components.developmentRelease

groupId = 'com.github.avohq'
artifactId = 'dev'
version = '2.0.1'
version = '2.0.2'
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions avoinspector/src/main/java/app/avo/inspector/AvoBatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void run() {
synchronized (events) {
SharedPreferences.Editor editor = sharedPrefs.edit();
editor.putString(avoInspectorBatchKey, new JSONArray(events).toString()).apply();
events = Collections.synchronizedList(new ArrayList<Map<String, Object>>());
}
}
}).start();
Expand All @@ -71,7 +72,7 @@ private void removeExtraElements() {

void enterForeground() {
final String savedData = sharedPrefs.getString(avoInspectorBatchKey, null);
events = Collections.synchronizedList(new ArrayList<Map<String, Object>>());

if (savedData != null) {
new Thread(new Runnable() {
@Override
Expand All @@ -91,9 +92,11 @@ public void run() {
}

events.add(event);
} catch (JSONException ignored) {}
} catch (JSONException ignored) {
}
}
} catch (JSONException ignored) { }
} catch (JSONException ignored) {
}
postAllAvailableEvents(true);
}
}).start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class KotlinActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

AvoInspector.setBatchSize(0)

val avoInspector = AvoInspector("MY_API_KEY",
application, AvoInspectorEnv.Dev,this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(view);

final AvoInspector avoInspector = new AvoInspector("MYEfq8E4FZ6Xkxlo9mTc",
getApplication(), AvoInspectorEnv.Staging, this);
getApplication(), AvoInspectorEnv.Dev, this);

binding.sendEventButton.setOnClickListener(view1 -> {
String eventName = binding.eventNameInput.getText().toString();
Expand Down

0 comments on commit b9d0a57

Please sign in to comment.