Pass an Activity company id to another and use in a database connection

Asked

Viewed 115 times

0

I am passing a user id through an Internet and intend to use this id in the second App. Even I believe it’s correct Take a look at the code:

I have to go from Activity to another user id:

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

receiving the id on 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 that?

1 answer

1


Use putExtra, in the Intent that calls the next Activity do:

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

On the call Activity do:

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

Another example can be found here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.