I am getting this error code while going through Android Studio 3.0 Development Essentials. "Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Intent?". Not sure why. The above code is what I am currently working with and "Intent" had automatically generated a question mark. The bottom code is what is shown in the book.
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if ((requestCode == request_code) && (resultCode == Activity.RESULT_OK)) {
if (data.hasExtra("returnData")) {
val returnString = data.extras.getString("returnData")
textView1.text = returnString
}
}
}
Code in book
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
if ((requestCode == request_code) && (resultCode == RESULT_OK)) {
if (data.hasExtra("returnData")) {
val returnString = data.extras.getString("returnData")
textView1.text = returnString
}
}
}
Fragments
the signature is (as of today)override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
so it's an Optional. – Martin Marconcini