Start activity after Toast message

android, android-intent, toast

Solution

Inside the "else" I added a thread that sleeps while Toast message is showing and after starts the next Activity.

...}else{           
        Toast.makeText(this.getApplicationContext(), "NO hay datos", Toast.LENGTH_LONG).show();             

        final Intent intent = new Intent(this, OtherActivity.class);        

        Thread thread = new Thread(){
           @Override
           public void run() {
                try {
                   Thread.sleep(3500); // As I am using LENGTH_LONG in Toast
                   startActivity(intent);   
               } catch (Exception e) {
                   e.printStackTrace();
               }
           } 
        };

        thread.start();
    }               

Problem

When my Activity don't get data from the DB, I show a Toast message saying about this. Then I recharge the previous Activity but this charge very fast and the Toast message still there a few seconds. I want this message duration but I don't know how to retard the init of the Activity that I want to start after message. ``` protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.aeiou); ... if(!oArrayList.isEmpty()){ ... }else{ Toast.makeText(this.getApplicationContext(), "NO hay datos", Toast.LENGTH_LONG).show(); Intent intent = new Intent(this, PreviousActivity.class); startActivity(intent); } ``` }

Original source