Boa tarde senhores, estou com um dúvida no meu código, eu preciso passar os dados de uma activity para outra porém quando eu coloco o valor ele abre a mesma tela duas vezes, ele está funcionando porém quando é colocado um valor no campo da activity ele abre outra tela porém com o valor informado, Poderiam me ajudar ? Segue abaixo meu código:
Activity que eu estou enviando :
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 que eu estou recebendo:
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));
}
}