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 plot it on the map.Before calling the second activity it shows a toast like notification on the screen but somehoe due to calling second activity that toast doesn't come up.My question is how can we delay the calling of second activity from this activity ?
Use the Call instruction to cause the current activity to find another specified activity and execute it. When that activity completes, control returns to the calling activity. The calling activity can pass parameter values to the called activity in two ways.
The Call instruction in an activity examines the In/Out value of each parameter in the called activity: If the parameter is declared as Out and the entire parameter page of the current activity is shared with the calling activity, then the value of the Out parameter in the call may be of the form param.name.
This interface can schedule code to run once after a specified delay or at fixed time intervals. To run a piece of code once after a delay, we can use the schedule method: The Classname::someTask part is where we specify the method that will run after the delay: To run a task at fixed time intervals, we can use the scheduleAtFixedRate method:
This tutorial will describe two ways to implement delays in Java. 2. A Thread -Based Approach When a Java program runs, it spawns a process that runs on the host machine. This process contains at least one thread – the main thread – in which the program runs.
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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With