Toast消息后启动活动

Jos*_*984 1 android toast android-intent

当我的Activity没有从数据库中获取数据时,我会显示Toast消息,说明这一点.然后我充电前一个活动,但这个充电非常快,Toast消息仍然存在几秒钟.我想要这个消息持续时间,但我不知道如何延迟我希望在消息后启动的Activity的init.

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);   
}       
Run Code Online (Sandbox Code Playgroud)

}

Jos*_*984 5

在"else"中,我添加了一个线程,当Toast消息显示并且在启动下一个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();
    }               
Run Code Online (Sandbox Code Playgroud)