Crash when scheduling jobs at Application's onCreate method
See original GitHub issueI have 2 types of jobs which runs at application’s onCreate in the following sequence:
EventJobUploader.schedulePeriodicJob(); EventJobUploader.runJobImmediately(); FavoriteJob.schedulePeriodicJob(); FavoriteJob.runJobImmediately();
Implementation of jobs methods a similar:
public static void runJobImmediately(){
new JobRequest.Builder(EventJobUploader.TAG)
.setExecutionWindow(TimeUnit.SECONDS.toMillis(10), TimeUnit.SECONDS.toMillis(20))
.build()
.schedule();
}
public static void schedulePeriodicJob(){
new JobRequest.Builder(EventJobUploader.TAG)
.setPeriodic(TimeUnit.MINUTES.toMillis(15), TimeUnit.MINUTES.toMillis(5))
.setUpdateCurrent(true)
.setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)
.build()
.schedule();
}
And on several devices (unknown, sentry did not provide any info about them, sorry) I’ve got crash with the following stacktrace:
android.database.sqlite.SQLiteException: table jobs already exists (code 1)
at dalvik.system.NativeStart.main
at com.android.internal.os.ZygoteInit.main
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
at java.lang.reflect.Method.invoke
at java.lang.reflect.Method.invokeNative
at android.app.ActivityThread.main
at android.os.Looper.loop
at android.os.Handler.dispatchMessage
at android.app.ActivityThread$H.handleMessage
at android.app.ActivityThread.access$1300
at android.app.ActivityThread.handleBindApplication
at android.app.Instrumentation.callApplicationOnCreate
at xxx.Application.onCreate
at xxx.EventJobUploader.schedulePeriodicJob
at com.evernote.android.job.JobRequest.schedule
at com.evernote.android.job.JobManager.schedule
at com.evernote.android.job.JobStorage.put
at com.evernote.android.job.JobStorage.store
at com.evernote.android.job.JobStorage.getDatabase
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked
at com.evernote.android.job.JobStorage$JobOpenHelper.onCreate
at com.evernote.android.job.JobStorage$JobOpenHelper.createJobTable
at android.database.sqlite.SQLiteDatabase.execSQL
at android.database.sqlite.SQLiteDatabase.executeSql
at android.database.sqlite.SQLiteStatement.executeUpdateDelete
at android.database.sqlite.SQLiteSession.executeForChangedRowCount
at android.database.sqlite.SQLiteConnection.executeForChangedRowCount
at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount
Issue Analytics
- State:
- Created 6 years ago
- Comments:14
Top Results From Across the Web
How to avoid IllegalStateException in JobScheduler?
We observe a rare IllegalStateException inside JobScheduler implementation when JobScheduler is accessed within Application.onCreate() method. I ...
Read more >Work manager crashes with "Apps may not schedule more ...
There are a few issues here. First of all anytime a job finishes, all jobs that aren't already running are rescheduled. Then, each...
Read more >Activity - Android Developers
onCreate (Bundle) is where you initialize your activity. ... please read the Application Fundamentals and Tasks and Back Stack developer guides.
Read more >Why does my multi-process Android app crash with a "java ...
This can be done by checking the process name in which Application.onCreate() is called. If the process name is the application id (example:...
Read more >How to make sense of Android crash logs | Bugsnag Blog
This is a convenient method if physical access to the device is an option, because the default UncaughtExceptionHandler in Android apps ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In android’s training its said we should leave our database connection open for as long as we possibly need to access it
Ref: https://developer.android.com/training/data-storage/sqlite.html
Also post post by a Google engineer (Dianne Hackborn)
Ref: https://groups.google.com/forum/#!msg/android-developers/nopkaw4UZ9U/cPfPL3uW7nQJ
A much simpler fix would be to just open the database connection once, and reuse it everywhere. You don’t need to open and close the database connection every time you read or write. SQLite itself takes care of thread safety.