I have two classes. the first one is MainActivity and the other is Orders The MainActivity.java is as follows
public class MainActivity extends Activity implements
ProductListAdapterListener {
private static final String TAG = MainActivity.class.getSimpleName();
public String itms1,itms2,itms3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
public void onAddToCartPressed(Product product) {
if(x==0)
{
itms1=",";
}
x++;
PayPalItem item = new PayPalItem(product.getName(), 1, product.getPrice(), Config.DEFAULT_CURRENCY,product.getSku());
productsInCart.add(item);
itms2 = item.getName();
itms2=itms2.concat(", ");
itms1=itms2.concat(itms1);
Toast.makeText(getApplicationContext(),
item.getName() + " added to cart! the cart now has:" + itms1, Toast.LENGTH_LONG).show();
}
}
Here, I am trying to use the variable itms1 in another class Orders.java which is as follows:
public class Orders extends MainActivity {
Button email, text;
public String msg=itms1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.orders);
email = (Button) findViewById(R.id.email);
text = (Button) findViewById(R.id.text);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String message = msg;
//check whether the msg empty or not
final HttpClient httpclient = new DefaultHttpClient();
final HttpPost httppost = new HttpPost("http://ramsproject.16mb.com/sendorder.php");
Thread thread = new Thread(new Runnable(){
@Override
public void run() {
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "01"));
nameValuePairs.add(new BasicNameValuePair("message",message));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
Toast.makeText(getBaseContext(), "Sent", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
}
});
}
}
Here, when I try to use variable itms1 in Orders.java, i get the value of itms1 as null. How do i use the value of that variable as it is as in MainActivity.java in another class?