Need help on delaying time interval between 2 activities

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Need help on delaying time interval between 2 activities

Postby kiranp » Fri Jan 15, 2010 4:39 pm

Hello everyone! :)

I've been having some problem recently.
I am making one application, where at the first screen, I have a button whose OnClickListener
displays a new screen or rather starts a new activity.
Also, I perform finish on the first activity so that the back button does not return me to the first screen.

Now, my problem is that... I am using Toast to show a particular message to the user.
But, because a new activity is started after that, the message I'm displaying dissappears IMMEDIATELY as a new
screen get's displayed.
So, what should be done to avoid this?
In what way, can I allow the Toast message to be displayed for long duration and start the new activity after the Toast message fades out ?

How can I delay the time between the showing of message and starting of activity?

I am posting my code here:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Button connectButton = (Button) findViewById(R.id.connectButton);
  3.  
  4. connectButton.setOnClickListener(new OnClickListener()
  5.  
  6. {  
  7.  
  8.         @Override  
  9.  
  10.         public void onClick(View v)
  11.  
  12.         {
  13.  
  14.         try
  15.  
  16.         {
  17.  
  18.                 //Few lines of code here..
  19.  
  20.  
  21.  
  22.                 Toast.makeText(Connect.this,"Connection successful!",Toast.LENGTH_LONG).show();
  23.  
  24.                 Intent intent = new Intent(Connect.this,NewUser.class);
  25.  
  26.                 startActivity(intent);
  27.  
  28.                 Connect.this.finish();
  29.  
  30.         }
  31.  
  32.         catch(Exception e)
  33.  
  34.         {
  35.  
  36.                 Toast.makeText(Connect.this,e.toString(),Toast.LENGTH_LONG).show();
  37.  
  38.         }
  39.  
  40.         }            
  41.  
  42. });
  43.  
  44.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4



Note: I've tried using Thread.sleep but it does not help... It gives a delay, before showing the message.
I've even tried placing it at different positions, but still no luck.

The same problem also occurs when I try to do animation.
If I dont start the activity, then I can see the animation properly.
But when I insert the startActivity() part again, the animation is visible for a very VERY short duration of time :(

I need to somehow increase the duration between these operations OR find some other way to start new activity.

Please help me out soon. :)
Thanks.
A person without a sense of humor is like a wagon without springs. It's jolted by every pebble on the road.

:)
kiranp
Developer
Developer
 
Posts: 28
Joined: Sat Aug 01, 2009 2:57 pm
Location: India

Top

Postby jwei512 » Sat Jan 16, 2010 11:14 pm

Do you need the toast to display before the next activity starts?

If that's not a requirement, then couldn't you just start the toast in the onCreate of the new Activity? And typically the toast will actually appear first before the rest of the activity renders so it will give it the "effect" that the toast was "called first"

However, if it's really important that the entire length of the toast is displayed before the other Activity starts... then we'll have to think of something else...
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Majestic-12 [Bot] and 5 guests