Reputation:
The MainActivity.kt recieve the latitude and longtitude
val intent = Intent(this@MainActivity,MapsActivity::class.java)
intent.putExtra("latitude", latitude)
intent.putExtra("longitude", longitude)
And then pass to MapsActivity.kt
val intent = Intent(this@MapsActivity,MainActivity::class.java)
val lat=intent.getStringExtra("latitude").toDouble()
val lon=intent.getStringExtra("longtitude").toDouble()
And when I run the application I get a errors while I go to MapsActivity
What is the main cause of this problem and how can I pass the values in the correct way?
Upvotes: 1
Views: 745
Reputation: 75798
Set
val intent = Intent(this@MainActivity,MapsActivity::class.java)
intent.putExtra("latitude", latitude!!)
intent.putExtra("longitude", longitude!!)
startActivity(intent)
Get
var bundle :Bundle ?=intent.extras
var latitude = bundle!!.getString("latitude").toDouble()
var longitude = bundle!!.getString("longitude").toDouble()
Upvotes: 3