zinnah1995
zinnah1995

Reputation: 25

Not getting passing data from Activity to activity

I am not getting data which i passed from another Activity using intent.putExtra. Overall it is also not showing errors. I am new to Android and Kotlin

Activity One

        i2.setOnClickListener(View.OnClickListener {
            var i = Intent(this,Courses::class.java)
            i.putExtra("semester",'2')
            startActivity(i)
        })

Activity Two

var semester:String? = null
semester = intent.getStringExtra("semester")

Not getting any data Just null and also not getting error. I tested it to show using Toast

Upvotes: 0

Views: 71

Answers (2)

Rander Gabriel
Rander Gabriel

Reputation: 647

Use Double quotes instead

i.putExtra("semester","2")

Upvotes: 1

Ariel
Ariel

Reputation: 1119

Try like this, it should work.

i2.setOnClickListener(View.OnClickListener {
            Intent i = new Intent(this,Courses.class)
            i.putExtra("semester",'2')
            startActivity(i)
        })

In second activity try this in OnCreate method:

    Intent intent = getIntent();
    savedInstanceState = intent.getExtras();
    char exampleVariable = savedInstanceState.get("semester");

Upvotes: 0

Related Questions