(Android Studio) Problems with OnRestart eating the main interface

0

Instead of the app showing the interface below, it pulls the OnRestart method straight and displays "Program Restarted" when I open the app. How can I correct that ?

Code:

TextViewtInforme;EditTexttValor;ButtonbtDescobrir;protectedstaticfinalStringCATEGORIA="Exercicio";

@Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(CATEGORIA, getClassName() + ".onCreate()) chamado: " + savedInstanceState);
    TextView t = new TextView(this);
    t.setText("Programa reiniciado");
    setContentView(t);
    setContentView(R.layout.activity_exercicio1);
    tInforme = (TextView) findViewById(R.id.tInforme);
    tValor = (EditText) findViewById(R.id.tValor);
    btDescobrir = (Button) findViewById(R.id.btDescobrir);}
    public void setbtDescobrir(View v) {

        String guessStr = tValor.getText().toString();
        int theGuess = Integer.parseInt(guessStr);
        int tValor = theGuess%2;
        if (tValor == 0){
            AlertDialog alertDialog;
            alertDialog = new AlertDialog.Builder(this).create();
            alertDialog.setTitle("O número é : ");
            alertDialog.setMessage("O número é par !");
            alertDialog.show();
        }
        else if (tValor == 1){
            AlertDialog alertDialog;
            alertDialog = new AlertDialog.Builder(this).create();
            alertDialog.setTitle("O número é : ");
            alertDialog.setMessage("O número é ímpar !");
            alertDialog.show();
        }





}

@Override
    public void OnRestart()
    {
        super.onRestart();
        Log.i(CATEGORIA, getClassName() + ". onRestart() chamado.");
    }
    private String getClassName()
{
    String s = getClass().getName();
    return s.substring(s.lastIndexOf("."));}

}

    
asked by anonymous 14.06.2017 / 18:17

1 answer

0

I think the problem is linked to this part of the code.

setContentView(t);
setContentView(R.layout.activity_exercicio1);

Well, you are placing your main view as:

 TextView t = new TextView(this);
t.setText("Programa reiniciado");

Even if you call the

setContentView(R.layout.activity_exercicio1);

It will not work because it draws only the first setContentView. I believe the correct thing to do is remove this line:

setContentView(t);
    
14.06.2017 / 19:07