Two Intents starting the same Activity

1

I have a button to add a Tip and I have another button to edit the already created Tip. I would like to use the same Creation Activity, when it is for editing it would pull the data already created. I'm in doubt how to make the Intent code, I can not. You're not pulling the dice. I'm trying like this:

{ Intent novadica = getIntent();
        if (novadica==null){

        enviardica.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                ParseObject dica = new ParseObject("Dicas");



                dica.put("nome", edttitulodica.getText().toString());
                dica.put("conteudoDica", edtconteudodica.getText().toString());
                dica.put("resumo", resumoChamadaDica.getText().toString());



                dica.saveInBackground(new SaveCallback() {
                    @Override
                    public void done(ParseException e) {


                        Toast.makeText(Inclusaodedica.this, "Dica enviada com sucesso.", Toast.LENGTH_LONG).show();

                        startActivity(new Intent(getApplicationContext(), MainActivity.class));
                    }
                });


            }
        });}else{

            Intent editardica = getIntent();
          String rdicaObjectId = editardica.getStringExtra("dicaObjectId");

            final ParseQuery <ParseObject> dica = new ParseQuery<ParseObject>("Dicas");
            dica.getInBackground(rdicaObjectId, new GetCallback<ParseObject>() {
                @Override
                public void done(final ParseObject object, ParseException e) {


                    edttitulodica.setText(object.getString("nome"));
                    edtconteudodica.setText(object.getString("conteudoDica"));
                    resumoChamadaDica.setText(object.getString("resumo"));

                    enviardica.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {



                            object.put("nome", edttitulodica.getText().toString());
                            object.put("conteudoDica", edtconteudodica.getText().toString());
                            object.put("resumo", resumoChamadaDica.getText().toString());


                            object.saveInBackground(new SaveCallback() {
                                @Override
                                public void done(ParseException e) {


                                    Toast.makeText(Inclusaodedica.this, "Dica alterada com sucesso.", Toast.LENGTH_LONG).show();

                                    startActivity(new Intent(getApplicationContext(), MainActivity.class));
                                }
                            });





                        }
                    });

Can anyone help me?

    
asked by anonymous 16.11.2016 / 00:24

1 answer

2

I would pass a boolean as Extra to another Activity:

Instead of:

startActivity(new Intent(getApplicationContext(), MainActivity.class));

Make:

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("is_new", true);
startActivity(intent);

In the other Activity, please confirm:

Bundle extras = getIntent().getExtras();
if(extras != null){
   if(extras.getBoolean("is_new", false)){
       //se a váriavel "is_new" estiver como true entra aqui
   }else{
       //se ela estiver false, ou seja, é edição, entra aqui
   }
}
    
16.11.2016 / 12:34