Sending data between View and Edit Activity [closed]

2

I'm developing a service scheduling system and in a ListView I get the data from a client and move on to a Query Activity. I created an edit menu and would like to pass this same data to the new activity, but I can only open the Activity without passing the data of this client.

Can you help me?

The code is attached. In this activity it selects an item from the list and throws the client object to a second activity, which is just for querying the data:

public class AgendadoDiaActivity extends AppCompatActivity {

private ListView listadeAtendimentos;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_agendado_dia);

    listadeAtendimentos = (ListView) findViewById(R.id.lista_atendimentos);

    listadeAtendimentos.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> lista, View item, int position, long id) {
            Clientes cliente = (Clientes) listadeAtendimentos.getItemAtPosition(position);
            Intent pesquisa = new Intent(AgendadoDiaActivity.this, ViewCadastroAtendimentosActivity.class);
            pesquisa.putExtra("cliente", cliente);
            startActivity(pesquisa);
        }
    });

In the onCreate of this Activity it takes the object that I sent in the extra and populates through the fill-in () method the items in the list.

public class ViewCadastroActivitiesActivity extends AppCompatActivity {

private HelperViewCadastroAtendimentos helper;
private HelperCadastroAtendimentos helperCadastro;
private Clientes cliente;
private Intent pesquisa;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_cadastro_atendimentos);

    helper = new HelperViewCadastroAtendimentos(this);

    pesquisa = getIntent();
    cliente = (Clientes) pesquisa.getSerializableExtra("cliente");
    if(cliente != null){
        helper.preencheFormulario(cliente);
    }
}

In this activity you have an edit button, which calls another editing activity. It is in it that I can not get these same data and play the values of bd.

    
asked by anonymous 18.10.2016 / 20:14

2 answers

3

To complement the answer from @Leonardo Dias the use of the code passing the extra by the intent and more advised to do for primitive data, such as int, byte, short, double and long and String that is an object but in this specific case and treated as primitive type. When it is necessary to send an object it is advisable to use it as follows:

Bundle bundle = new Bundle();
bundle.putSerializable("value", SeuObjeto);
intent.putExtras(bundle);

....

Remembering that your object should implement Serializable.

    
19.10.2016 / 06:48
1

Raul, show your code, it's best to be able to help.

Here is an example of how to pass data between Activitys:

Intent intent = new Intent(LoginActivity.this, UserSignupActivity1.class);
intent.putExtra("user_name", nomeUser);
intent.putExtra("user_mail", emailUser);
intent.putExtra("facebookId", userId);
startActivity(intent);

And here's an example of how to get in the second Activity:

Bundle extras = getIntent().getExtras();
if(extras != null){
     Intent in = getIntent();
     String nomeUserFacebook = in.getStringExtra("user_name");
     String emailUserFacebook = in.getStringExtra("user_mail");
     String idUserFacebook = in.getStringExtra("facebookId");
}
    
18.10.2016 / 20:32