我是 android 开发的菜鸟,我试图在两个类之间传递一个变量。根据我的调试器,该值是在第一类中设置的,但无论出于何种原因,它在第二类中返回 null。我最初尝试通过将变量设为 public 和 static 来传递值,然后我尝试将值放在 Extras 中。两种方法在第二个 Activity 中都返回 null。我已经清理了项目但没有成功。似乎它只是不允许重置字符串的值。非常感谢任何解决此问题的帮助。
我的代码
甲级
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;
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());
}