Pro Android with Kotlin


Download 5.42 Mb.
Pdf ko'rish
bet113/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   109   110   111   112   113   114   115   116   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

128
CHAPTER 8: APIs
from version 2 to 3 and need another column, childCount. Inside the migs array from the 
previous code, you then write the following:
//...
object : Migration(1,2) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE components "+
"ADD COLUMN salary INTEGER DEFAULT 0;")
}
}
//...
object : Migration(2,3) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE components "+
"ADD COLUMN childCount INTEGER DEFAULT 0;")
}
}
//...
object : Migration(1,3) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE components "+
"ADD COLUMN salary INTEGER DEFAULT 0;")
db.execSQL("ALTER TABLE components "+
"ADD COLUMN childCount INTEGER DEFAULT 0;")
}
}
//...
If you provide small-step migrations as well as large-step migrations, the latter will have 
precedence. This means if you have migration plans 1 
→ 2, 2 → 3, and 1 → 3 and the 
system demands a migration 1 
→ 3, the plan 1 → 3 will run, not the chain 1 → 2 → 3.
Scheduling
With user experience in mind, running tasks in an asynchronous manner is an important 
matter. It is vital that no lengthy operations disturb the front-end flow, leaving the impression 
that your app is doing its job fluently.
It is not too easy to write stable apps that have important parts running in background, 
though. The reasons for that are many: the device might get powered off on demand or 
because of low battery, or the user might have started a more important app with higher 
priority, expecting to temporarily run background jobs in a low-priority mode. Also, the 
Android OS might decide to interrupt or postpone background jobs for other reasons such 
as a resource shortage or because a timeout condition applies. And with the advent of 
Android 8, it has become even more important to think about clever ways of performing 
background tasks since this version imposes severe restrictions on the background 
execution of program parts.
For running jobs in an asynchronous manner, several techniques exist, all of them with 
downsides and advantages.



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   109   110   111   112   113   114   115   116   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling