I can not call Activity for minutes without needing a button

0

Good afternoon, I'm starting to learn ansdroid, and I'm in the same tightening, I can not change the screen for minutes, where am I going wrong and can someone give me an optimization?

public void passartelacategoria(View view) {
        final int MILISEGUNDOS = 3000;
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                Intent chamando = new Intent(MainActivity.this, categoriaActivity.class);
                MainActivity.this.startActivity(chamando);
                MainActivity.this.finish();
            }
        }, MILISEGUNDOS);
    }
    
asked by anonymous 20.04.2018 / 17:08

1 answer

0

The code is correct, but probably because it is setting the time there inside the method and, at the end, it may be influencing.

Try declaring the time up there in your Activity, for example:

public class MainActivity extends Activity {

    private static int TIME_OUT = 3000; 

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

        ...
}
    
20.04.2018 / 17:18