user3231800 user3231800 - 5 months ago 16
Android Question

Android intent getting data error

I have a problem with android intent, it work and open a new window but when take data from mainactivity all of this is 0 but when i check it have the correct value.
How it's possible?

This is the main code:

nst = Integer.parseInt(ConfMat[1][1]);
nrt = Integer.parseInt(ConfMat[2][2]);
ndx = Integer.parseInt(ConfMat[3][3]);
nsx = Integer.parseInt(ConfMat[4][4]);
Intent intent2 = new Intent(getApplicationContext(),Server.class);
Bundle bundle = new Bundle();
intent2.putExtra("stop", nst);
intent2.putExtra("rotatoria", nrt);
intent2.putExtra("destra", ndx);
intent2.putExtra("sinistra", nsx);
Log.i(TAG, "STOP " + nst + " ,rt " + nrt+" ,dx "+ndx+" ,sx "+nsx);
intent2.putExtras(bundle);
startActivity(intent2);


The log result is :
STOP 1 ,rt 1 ,dsx 1 ,sx 1

then i get the data in the intent:

super.onCreate(savedInstanceState);
setContentView(R.layout.serversocket);


Intent intent = getIntent();
Bundle bundle = intent.getExtras();
nsts = bundle.getInt("nst");
nrts = bundle.getInt("nrt");
ndxs = bundle.getInt("ndx");
nsxs = bundle.getInt("nsx");

try{

Log.i(TAG, "Nell server Stop " + nsts + " ,rt" + nrts + " ,dx" + ndxs + " ,sx" + nsxs);


Now the Log return:
Nell server Stop 0 ,rt 0 ,dx 0 ,sx 0

Thank for help.

Answer

I think you have your keys and values mixed up. Try:

    nsts = bundle.getInt("stop");
    nrts = bundle.getInt("rotatoria");
    ndxs = bundle.getInt("destra");
    nsxs = bundle.getInt("sinistra");
Comments