1
Good afternoon gentlemen, I have a question in my code, I need to pass the data from one Activity to another but when I put the value it opens the same screen twice, it is working but when a value is placed in the field of Activity it opens another screen but with the value informed, Could you help me ? Follow my code below:
Activity I am sending :
public class NovaCor extends AppCompatActivity {
public Button botao1;
botao1 = (Button) findViewById( R.id.btn1);
public void botao1(View v)
{
if (bool == false) {
//String str1 = this.botao1.getBackground().toString();
ColorDrawable buttonColor = (ColorDrawable) this.botao1.getBackground();
int colorInt = buttonColor.getColor();
String colorHex = Integer.toHexString(colorInt);
Intent intent = new Intent(getApplication(), CriarCateg.class);
intent.putExtra("KEY", colorHex);
this.startActivity(intent);
this.finish();
}
}
}
Activity I am getting:
public class CriarCateg extends AppCompatActivity {
private EditText descricao;
public EditText cor;
public Button altera;
public void onCreate(@Nullable Bundle savedInstanceState) {
descricao = (EditText) findViewById( R.id.textViewDescrCateg);
cor = (EditText) findViewById( R.id.txtviewcorcateg);
altera = (Button) findViewById( R.id.alterarcor);
Bundle bundle = this.getIntent().getExtras();
if (bundle != null){
String teste = bundle.get("KEY").toString();
this.cor.setText("#" + teste);
altera.setBackgroundColor(Color.parseColor("#"+teste));
}
}
When you click the button you just want to pass the Bundle and not access the other Activity?
– Murillo Comino
explain better what you want to do, got a little confused
– Murillo Comino
So I have a screen and when I click on the "Create Category" button it starts a new Activity with a new layout, within the "Create Category" has another button called "Select the color" which starts another Activity with another layout and with a color palette. When a color is selected it opens again the "Create Category" Activity with the selected color, that is, it keeps the Activity "create category" open twice. What I wanted is that instead of him opening up again, he filled in what’s open, but my tests didn’t work.
– Dev
resolved with my reply???
– Murillo Comino