Skip to content

Commit

Permalink
[SVN] r3191 Inventory in /Projects/Inventory/
Browse files Browse the repository at this point in the history
[EXP] #173 workaround for Application.onCreate > startService crashes
  • Loading branch information
TWiStErRob committed Oct 29, 2020
1 parent 8d711d2 commit 3b871b8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions android/src/main/java/net/twisterrob/inventory/android/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ public static Database db() {

@Override public void onStart() {
super.onStart();
try {
// Quick workaround to prevent crashes on startup.
// Only foreground apps can startService(), at this point it's not foreground yet.
// https://github.com/TWiStErRob/net.twisterrob.inventory/issues/173
startServices();
} catch (RuntimeException ex) {
LOG.warn("Cannot start services", ex);
}
}

private void startServices() {
// open a database first, this should lock any other accesses, so it's clearer when the DB open fails
startService(new Intent(DatabaseService.ACTION_OPEN_DATABASE).setPackage(getPackageName()));
// run vacuum next, it's quick and most of the time does nothing anyway
Expand Down

0 comments on commit 3b871b8

Please sign in to comment.