У меня проблема с методом «Onpause» в моем приложении.Когда я нахожусь в своей активности ScanView и нажимаю «кнопку назад», мое приложение вылетает.
Здесь мой список щелчков на моей MainActivity.
btn!!.setOnClickListener {
val intent = Intent(this@MainActivity, ScanActivity::class.java)
//startActivity(intent)
startActivityForResult(intent,PICK_CONTACT_REQUEST)
}
Здесь мой класс ScanActivity
class ScanActivity : Activity(), ZXingScannerView.ResultHandler {
private var mScannerView: ZXingScannerView? = null
public override fun onCreate(state: Bundle?) {
super.onCreate(state)
mScannerView = ZXingScannerView(this) // Programmatically initialize the scanner view
setContentView(mScannerView) // Set the scanner view as the content view
}
public override fun onResume() {
super.onResume()
mScannerView!!.setResultHandler(this) // Register ourselves as a handler for scan results.
mScannerView!!.startCamera() // Start camera on resume
}
public override fun onPause() {
super.onPause()
mScannerView!!.stopCamera()
}
override fun handleResult(p0: com.google.zxing.Result?) {
val data = Intent()
data.putExtra("code", p0!!.text)
setResult(Activity.RESULT_OK, data)
finish()
mScannerView!!.resumeCameraPreview(this)
}
В моем MainActivity указан результат Onactivity
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
if (requestCode == PICK_CONTACT_REQUEST) {
if (resultCode == Activity.RESULT_OK) {
val cb = data.getStringExtra("code")
println(cb)
tvresult.text = cb.toString()
}}
}
И, наконец, код ошибки.
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=0, data=null} to activity {fr.tais.riocb/fr.tais.riocb.MainActivity}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data
at android.app.ActivityThread.deliverResults(ActivityThread.java:4268)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
at android.app.ActivityThread.-wrap19(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data
at fr.tais.riocb.MainActivity.onActivityResult(Unknown Source:2)
at android.app.Activity.dispatchActivityResult(Activity.java:7276)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4264)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
at android.app.ActivityThread.-wrap19(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
У вас есть идея по моей проблеме?
Спасибо