1

I'm a noob to android development and I am attempting to pass a variable between two classes. According to my debugger, the value is being set in the first class, but for whatever reason it is returning null in the second class. I initially tried passing the value by making the variable public and static and then I attempted placing the value in the Extras. Both methods returned null in the second Activity. I have clean the project with no success. It seems as if it just won't won't allow the value of the string to be reset. Any help resolving this is greatly appreciated.

My Code

CLASS A

case R.id.profile:      

        selection = (Integer)v.getTag();
        Log.e("Selection", String.valueOf(selection));

        if(LandingActivity.user_isClient){
            adapter_email = (listData.get(selection)).get("Email"); //<--debugger showing value as set here 
            Log.e("Adapter Email", adapter_email);
            Intent myIntent = new Intent("com.tpssquared.kuttime.PROFILE_BARBER_VIEW");
            myIntent.putExtra("ADAPTER_EMAIL", adapter_email); //<--debugger showing value as set here too
            c.startActivity(myIntent);              
        }else{
            adapter_email = (listData.get(selection)).get("Client_Email"); //<--debugger showing value as set here
            Log.e("Adapter Email", adapter_email);
            Intent myIntent = new Intent("com.tpssquared.kuttime.PROFILE_CLIENT_VIEW");
            myIntent.putExtra("ADAPTER_EMAIL", adapter_email); //<--debugger showing value as set here too
            c.startActivity(myIntent);  
        }

        break;

CLASS B

barber_email_string ="";//Deubugger showing value as null and not "". WHY?
try{
        if(barber_email_string.equals(null)||barber_email_string.equals("")){
            barber_email_string = getIntent().getStringExtra("ADAPTER_EMAIL");          

            if(barber_email_string.equals(null)||barber_email_string.equals("")){
                barber_email_string = Uri.encode(MyAppointments_ListAdapter.adapter_email);
                Log.e("BPV email",barber_email_string);
            }
        }
        Log.e("BPV email",barber_email_string);
    }catch(Exception e){
        e.printStackTrace();
        Log.e("On Create", e.toString());
    }
DollaBill
  • 239
  • 1
  • 3
  • 15
  • try [this](http://stackoverflow.com/questions/3848148/sending-arrays-with-intent-putextra) – Zyoo Sep 18 '13 at 18:45

1 Answers1

1

You aren't passing a Bundle to Activity B, you're passing a String extra. So when you call getExtras(), there's nothing there. You can simply call getStringExtra() on the Intent itself to get your string.

barber_email_string = getIntent().getStringExtra("ADAPTER_EMAIL");

Alternatively, you could create a new Bundle, package the string into that, and pass it with putExtras(myBundle), but that's overkill for a single string.

Geobits
  • 22,218
  • 6
  • 59
  • 103