-1

I have two activity , the first activity pass value to Second activity but the value is sent incorrectly that is the code for onclick in first activity

 Intent nextScreen = new Intent(EgyptActivity.this, ViewRecord.class);

            nextScreen.putExtra("name", "1".toString() );
            startActivity(nextScreen);

second activity code is

Bundle i = getIntent().getExtras();

        Receiving the Data
     String name = i.getString("name");
         Log.i ("name", name);
    String ne="1";
    Log.i ("ne", ne);
    if (name==ne)
    {Log.i ("info", ne);}
     if (name!=ne) 

     {Log.i ("info", "2");}

        }

LogCat

name: 1
ne: 1
info: 2

so please would any one tell me why the value name!=ne

New Ques
  • 107
  • 1
  • 1
  • 4

1 Answers1

0

To do a proper string comparison use:

if (name.equals(ne))
{
    Log.i ("info", ne);
}
if (!name.equals(ne))
{
   Log.i ("info", "2");
}
dymmeh
  • 22,247
  • 5
  • 53
  • 60
  • no the problem "name" sent to second activity not equal "1" and not equal "ne" , while in logCat they are equal – New Ques Sep 11 '13 at 19:43
  • @user2536135 - replace your if statements with what I posted. You are not correctly comparing the strings which is why they are showing as not equal – dymmeh Sep 11 '13 at 19:57
  • thanks dymmeh , it works with me – New Ques Sep 12 '13 at 04:39
  • No problem. If it worked for you make sure to mark it as the correct answer by clicking the checkbox next to the answer. – dymmeh Sep 12 '13 at 13:19