Issue
I want to pass a value from one avtivity to another activity by use intent.. Im not getting the value im getting as null.. There is no error in my logcat. Any help would appreciated. thanks in advance.
First activity
Intent intent = new Intent(Nexttopic.this, Quesans.class);
String name = getIntent().getStringExtra("name");
intent.putExtra("TopicName", tname);
intent.putExtra("Topicid", topicid);
intent.putExtra("LevelName",TAG_LEVELNAME);
intent.putExtra("Levelid",TAG_LEVELID);
intent.putExtra("Groupid",TAG_GROUPID);
startActivity(intent);
Second activity
Intent i=getIntent();
name=i.getStringExtra(tname);
tid=i.getStringExtra(topicid);
lid=i.getStringExtra(TAG_LEVELID);
gid=i.getStringExtra(TAG_GROUPID);
System.out.println("Result :"+name);
System.out.println("Result :"+tid);
System.out.println("Result :"+lid);
System.out.println("Result :"+gid);
Solution
You need to refer to the names of extra fields you have set while calling another activity. So Change this :
Intent i=getIntent();
name=i.getStringExtra(tname);
tid=i.getStringExtra(topicid);
lid=i.getStringExtra(TAG_LEVELID);
gid=i.getStringExtra(TAG_GROUPID);
System.out.println("Result :"+name);
System.out.println("Result :"+tid);
System.out.println("Result :"+lid);
System.out.println("Result :"+gid);
to this :
Intent i=getIntent();
name=i.getStringExtra("TopicName");
tid=i.getStringExtra("Topicid");
lid=i.getStringExtra("Levelid");
gid=i.getStringExtra("Groupid");
System.out.println("Result :"+name);
System.out.println("Result :"+tid);
System.out.println("Result :"+lid);
System.out.println("Result :"+gid);
hope it helps.
Answered By - Misha Bhardwaj
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.