Я разрабатываю библиотеку, которая состоит из 4 заданий [A, B, C, D]
Activity A is launched by user-app
A launches B and expect response on `onActivityResult`.
B finishes by setting RESULT_OK
A launches C and expect response on `onActivityResult`.
C do some Image processing on a 4096x2160 image and finishes by setting RESULT_OK
A launches D and expect response on `onActivityResult`.
D finishes by setting RESULT_OK
A set it's result as RESULT_OK finishes.
The result is returned to the user-app.
Проблема возникает после этого шага C do some Image processing on a 4096x2160 image and finishes by setting RESULT_OK
после этого шага, задание A уничтожается сзади и вызывается метод onCreate в A, т. е. снова вызывается A launches B and expect response on onActivityResult.
.Как я могу сделать это лучше, чтобы не было неожиданных отключений.
Вот код деятельности A:
class SelectPackage : AppCompatActivity() {
companion object {
internal const val RES_PACKAGE_CANCEL = 100
internal const val RES_PACKAGE_OK = 104
internal const val RES_EDITACTIVITY_CANCEL = 101
internal const val RES_EDITACTIVITY_OK = 105
internal const val RES_SUMMARY_CANCEL = 102
internal const val RES_SUMMARY_OK = 103
}
private val REQ_CODE = 1023
private val data: Data by lazy { makeDataObject() }
private fun makeDataObject(): Data {
val data = Data()
data.clientToken = intent.getStringExtra(clientToken)
....
....
data.screenSize = intent.getStringExtra(screenSize)
return data
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_select_package)
Log.d("YYY", "Activity started again")
val i = Intent(this, Packages::class.java)
i.putExtra(SelectPackage.DATA, data)
startActivityForResult(i, REQ_CODE)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQ_CODE) {
when (resultCode) {
RES_PACKAGE_CANCEL -> {
setResult(AppCompatActivity.RESULT_CANCELED)
finish()
}
RES_PACKAGE_OK -> {
if (data != null) {
val intent = Intent(this, EditActivity::class.java)
intent.putExtra(SelectPackage.DATA, data.getSerializableExtra(SelectPackage.DATA))
intent.putExtra(Pkgs.TAG, data.getSerializableExtra(Pkgs.TAG))
startActivityForResult(intent, REQ_CODE)
}
}
RES_EDITACTIVITY_CANCEL -> {
setResult(AppCompatActivity.RESULT_CANCELED)
finish()
}
RES_EDITACTIVITY_OK -> {
if (data != null) {
val intent = Intent(this, SummaryActivity::class.java)
intent.putExtra(SelectPackage.DATA, data.getSerializableExtra(SelectPackage.DATA))
intent.putExtra(Pkgs.TAG, data.getSerializableExtra(Pkgs.TAG))
startActivityForResult(intent, REQ_CODE)
}
}
RES_SUMMARY_CANCEL -> {
setResult(AppCompatActivity.RESULT_CANCELED)
finish()
}
RES_SUMMARY_OK -> {
if (data != null) {
val intent = Intent()
intent.putExtra(SelectPackage.packageName, data.getStringExtra(SelectPackage.packageName))
intent.putExtra(SelectPackage.packageId, data.getStringExtra(SelectPackage.packageId))
intent.putExtra(SelectPackage.packagePrice, data.getFloatExtra(SelectPackage.packagePrice,0f))
setResult(AppCompatActivity.RESULT_OK)
finish()
}
}
}
}
}
}