I want to reveive value that i passed throught Intent from activity to another and access it, but it's showing:
Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
So here what i did... in the Login Activity I passed username thourgh Intent:
val intent = Intent(this@LoginActivity,MainActivity::class.java)
intent.putExtra("username", "johnDoe")
startActivity(intent)
Main Activity
class MainActivity : AppCompatActivity() {
val username = intent.getStringExtra("username")
private val firebaseHelper = FirebaseHelper(username)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Toast.makeText(applicationContext, username.toString(), Toast.LENGTH_LONG).show()
}
override fun onStop() {
super.onStop()
firebaseHelper.deleteDriver()
}
}
Fore example: if i use val username = intent.getStringExtra("username")
it will work, but then i will get problem with firebaseHelper.deleteDriver()
.
i don't know where i missed it, but hope there's solution you can make guys