Pass The Value From Activity To Next Activity In Android
I have developed one android application. This is my first activity: public class ViewCartActivity extends Activity {  String mGrandTotal; @Override protected void onCreate(Bundle
Solution 1:
change getIntent().getExtras().getString(total)
To:
getIntent().getStringExtra("GrandTotal"); 
Or
Stringtotal= in.getStringExtra("GrandTotal");
grandtotal.setText("Welcome ," + total);
Solution 2:
FirstActivity
publicclassViewCartActivityextendsActivity {
String mGrandTotal;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stubsuper.onCreate(savedInstanceState);
    setContentView(R.layout.viewcartactivity);
    ListViewmLstView1= (ListView) findViewById(R.id.listView1);
    TextViewmTxtViewGrandTotal= (TextView) findViewById(R.id.mTxtViewGrandTotalValue);
    ButtonmBtnSubmit= (Button) findViewById(R.id.mBtnSubmit);
    ViewCartAdaptermViewCartAdpt=newViewCartAdapter(
            ViewCartActivity.this);
    mLstView1.setAdapter(mViewCartAdpt);
    if (Constants.mItem_Detail.size() > 0) {
        DoublemGTotal= Double.parseDouble(Constants.mItem_Detail.get(0)
                .get(SingleMenuItem.KEY_TOTAL));
        for (inti=1; i < Constants.mItem_Detail.size(); i++) {
            mGTotal = mGTotal
                    + Double.parseDouble(Constants.mItem_Detail.get(i).get(
                            SingleMenuItem.KEY_TOTAL));
        }
        mGrandTotal = String.valueOf(mGTotal);
        mTxtViewGrandTotal.setText("$" + mGrandTotal);
    }
    mBtnSubmit.setOnClickListener(newOnClickListener() {
        @OverridepublicvoidonClick(View v) {
            // TODO Auto-generated method stubIntenti=newIntent(getApplicationContext(), CustomerLogin.class);
             i.putExtra("GrandTotal", mGrandTotal);
                startActivity(i);
        }
    });
SecondActivity
setContentView(R.layout.customer_login);
  Bundleb= getIntent().getExtras();
       Stringtotal= b.getString("GrandTotal");
    TextViewgrandtotal= (TextView) findViewById(R.id.grand_total);
     grandtotal.setText("Welcome ," + total );
Solution 3:
Either store the value in shared preferences in one activity and get the value from same preference in another activity.
Storing in preferences
          SharedPreferences preferences=getSharedPreferences(preferencename, MODE_PRIVATE);
          Editor preferenceEditor=preferences.edit();
          preferenceEditor.putString(key,value);
          preferenceEditor.putInt(key,value);
          preferenceEditor.commit();
Getting from preferences
         preferences=getSharedPreferences(config_prop.getConfigValue("sharedprefs"), MODE_PRIVATE);
         Stringstr=preferences.getString(key, defaultValue);
Also you can pass the values using intents.
Solution 4:
Just change
grandtotal.setText("Welcome ,"+getIntent().getExtras().getString(total));
to
grandtotal.setText("Welcome ,"getIntent().getExtras().getString(GrandTotal));
in second activity.
And remove
String s= getIntent().getStringExtra(mGrandTotal);
It should be
i.putExtra("GrandTotal", mGrandTotal);
from first activity on button click event. Because mGrandTotal is local activity variable. So you don't need to get it from intent
Post a Comment for "Pass The Value From Activity To Next Activity In Android"