我无法将字符串传递给另一个类。任何人都可以解决这个问题?感谢并非常感谢您的帮助。
一级
public class MainActivity extends Activity {
Intent myIntent;
Intent intent;
String n;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1=(Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
public void onClick(final View v) {
System.out.println("Pg1");
n="title";;
System.out.println("n1"+n);
System.out.println("p1getn "+getn());
myIntent=new Intent (v.getContext(),spg.class);
startActivityForResult(myIntent,0);
}
});
}
public String getn(){
System.out.println("nn"+n);
return n;
}
}
二等
public class spg extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sec);
MainActivity am = new MainActivity();
System.out.println("Pg2");
System.out.println("n2"+am.n);
System.out.println("getn2"+am.getn());
}
}