Pass the id of an enterprise from activity to another and use it in a connection with database

0

I am passing an id of a user through an intent and I intend to use this id in the second activity. I think it's okay to take a look at the code:

I have to pass this activity to another id of the user:

ltsunidades = (ListView) findViewById(R.id.ltsunidades);

            final ArrayAdapter<Tab_UC> adapter = new ArrayAdapter<Tab_UC>
                    (Selecionar_Unidade.this, android.R.layout.simple_list_item_1, lista);
            ltsunidades.setAdapter(adapter);

            //selecionando unidade
            ltsunidades.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView adapter, View viw, int posicao, long id) {
                    id = adapter.getItemIdAtPosition(posicao);
                    Intent it = new Intent(getBaseContext(), Empresa.class);
                    it.putExtra("id", id);
                    startActivity(it);
                }
            });

        }// end post execute
    }// end async task

getting the id in the second activity

Intent it = getIntent();               //aqui eu recebo o id da outra activity 
        id = it.getIntExtra("id",0);  // preciso saber ser esta certo?


                                   // e preciso usar esse "id " no lugar dessa 
                                     Preferencia e eu não sei como usar
        url = url.replace("par1", Preferencia.getCodEmpresa(this));
        Log.i("URL", "" + url);
    }

How can I do this?

    
asked by anonymous 07.04.2016 / 13:14

1 answer

1

Use putExtra, in the intent calling the next activity do:

 Intent i = new Intent(...);
    i.putExtra("Id", "123");

In the activity call do:

   Bundle b = getIntent().getExtras();
    Log.i("id", b.getString("Id", null));

Another example can be found here

    
07.04.2016 / 18:45