How to put some delay in calling an activity from another activity?

后端 未结 7 2322
难免孤独
难免孤独 2020-12-03 05:31

I have an application in which I\'m receiving a sms containing his location.On receiving sms it calls another activity to start and passes that location to that activity to

相关标签:
7条回答
  • 2020-12-03 05:55

    Try:

    Runnable r = new Runnable() {
            @Override
            public void run() {
               // if you are redirecting from a fragment then use getActivity() as the context.
              startActivity(new Intent(SplashActivity.this, MainActivity.class));
              // To close the CurrentActitity, r.g. SpalshActivity
              finish();
           }
    };
    
    Handler h = new Handler();
    // The Runnable will be executed after the given delay time
    h.postDelayed(r, 1500); // will be delayed for 1.5 seconds
    
    0 讨论(0)
  • 2020-12-03 05:57

    An example would be the following:

    Handler TimeDelay=new Handler();
                    if(previous=="geofence"){
    
    
    
                        tts.speak(previous,TextToSpeech.QUEUE_ADD,null, null);
                        Runnable r = new Runnable() {
                            @Override
                            public void run() {
                                /*
                                Intent intent = new Intent(
                                        MyBroadcastMessageReceiver.class.getName());
                                intent.putExtra("some additional data", choice);
                                someActivity.sendBroadcast(intent);*/
                                tts.speak(previous,TextToSpeech.QUEUE_ADD,null, null);
                            }
                        };
                        TimeDelay.postDelayed(r, 150000);
    
    0 讨论(0)
  • 2020-12-03 06:03

    You can do it with a Handler like this

        Handler h = new Handler(){
            @Override
            public void handleMessage(Message msg) {
    
                Intent i = new Intent().setClass(ctx, MainActivity.class);                  
                startActivity(i);
            }           
        };
    
        h.sendEmptyMessageDelayed(0, 1500); // 1500 is time in miliseconds
    
    0 讨论(0)
  • 2020-12-03 06:09

    Make an AsyncClass that does Thread.sleep() in the doInBackground() method, then navigate to your new activity in the your onPostExecute() method.

    Call your toast message and then execute the AsyncClass.

    0 讨论(0)
  • 2020-12-03 06:10

    You can use something like this:

     new Handler().postDelayed(new Runnable() {
                          @Override
                          public void run() {
    
                              Intent i=new Intent(SearxhJobs.this,JobsTypes.class);
                              startActivity(i);
                          }
                      }, 5000);
    

    Here it waits upto 5 seconds to launch activity.

    Hope it helps

    0 讨论(0)
  • 2020-12-03 06:11

    Simply set the layout!

     new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
    
                setContentView(R.layout.next); //where <next> is you target activity :)
    
                }
            }, 5000);
    
    0 讨论(0)
提交回复
热议问题