Splash Screen

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

Splash Screen

Postby and.modi » Mon Nov 10, 2008 10:16 pm

Hi,
I want to develop one game.
I have created two UI screens for the game using xml files. One of them is simple splashscreen with background and other one is having buttons to select several options.
What I want is,
When the game launches, it shows splashscreen for a while (like 2 seconds) and then shows the second screen automatically.
Can anyone please help me, that how can I do that?
If I can do that using activities and Intent, please inform me how can I do that.
Any link for that will be helpful.
I tried the book to look in to the book "Android, A programmer's Guide" but nothing is helpful
Thanks,
Mitul Modi
and.modi
Junior Developer
Junior Developer
 
Posts: 14
Joined: Sat Jul 26, 2008 9:17 am

Top

Postby tsucheck » Tue Nov 11, 2008 5:24 am

Did you try sending a delayed message to your first activity, when the timer pops you start the next activity. Have a look through the API demo app that comes with Android. Search for sendMessage in Android docs.
tsucheck
Developer
Developer
 
Posts: 29
Joined: Sun Feb 17, 2008 2:07 am

Postby and.modi » Tue Nov 11, 2008 2:19 pm

Thanks,
I will try that and let u know, if it works or not.
and.modi
Junior Developer
Junior Developer
 
Posts: 14
Joined: Sat Jul 26, 2008 9:17 am

Postby and.modi » Fri Nov 14, 2008 2:20 am

Hi,
I use code as follows. But the problem is that I am not getting the screen shown by main.xml file (first screen).
When I press back button from the screen viewed by menu.xml file (second view), it shows view by main.xml file (so it is there but doesn't come up). So now I don't understand why it doesn't come up in first place.


The code is as follows:

package com.naag;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import android.view.Window;
public class naag extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

//No Title bar will be displayed
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

try
{
Thread.sleep (2000);//delay for 2 seconds
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}


Intent menuLauch = new Intent (this, menu.class);
startActivity (menuLauch);

}
}


The menu.java file is as follows...

package com.naag;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class menu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);

//No Title bar will be displayed
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.menu);
}
}

I have also changed AndroidManifest.xml to use intents..

-------------------------------------------------------------------------------------------------------------------------------
I tried this method for my second and third screen and it is working fine and perfectly.
So I don't understan, that why its not working for first and second screen. Is it due to delay?

I got third view by adding this code in menu.java file:

Button contactButton = (Button) findViewById (R.id.contact);
contactButton.setOnClickListener ( new Button.OnClickListener()
{
public void onClick (View v)
{
launchContact();
}
});

and creating method which lauch new activity called contact and Contact class which set view as shown in 3.jpg file.
I can go from that contact screen to menu screen and menu screen to first screen shown in 4.jpg.

There are

By changing setContentView(R.layout.menu); after setContentView(R.layout.main); doesn't help.
As it provides only second view and that is without first even show up and its not there in history stack.

So please help me in this problem.

Thanks 4 your reply.
Attachments
1.jpg
The first screen when the application laucnh. Its not what I want. It should look like 4.jpg.
1.jpg (19.56 KiB) Viewed 443 times
and.modi
Junior Developer
Junior Developer
 
Posts: 14
Joined: Sat Jul 26, 2008 9:17 am

Postby and.modi » Fri Nov 14, 2008 2:21 am

This is the image of second screen of the application ...
Attachments
2.JPG
The menu screen which comes properly..
2.JPG (37.11 KiB) Viewed 442 times
and.modi
Junior Developer
Junior Developer
 
Posts: 14
Joined: Sat Jul 26, 2008 9:17 am

Postby and.modi » Fri Nov 14, 2008 2:24 am

Image of third screen displayed by clicking contact me button on menu.
Attachments
3.JPG
Third screen displayed by clicking contact me button on menu.
3.JPG (17.69 KiB) Viewed 441 times
and.modi
Junior Developer
Junior Developer
 
Posts: 14
Joined: Sat Jul 26, 2008 9:17 am

Top

Postby and.modi » Fri Nov 14, 2008 2:26 am

This is the screen shot when I press from the menu view. So this is loaded but is not displed at first time..

Also I want that when user enters in the menu screen, it should not return to this screen or this image must be clickble to retrun to menu.

I hope u get my point. :roll:

Thansk.
Attachments
4.JPG
this screen should load at first time..
4.JPG (27.36 KiB) Viewed 440 times
and.modi
Junior Developer
Junior Developer
 
Posts: 14
Joined: Sat Jul 26, 2008 9:17 am

Postby rmanromga » Fri Nov 14, 2008 4:07 am

Hi Here is how I do my splash screen. It displays for 5000 ms before my main menu kicks in...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Splash extends Activity {
  2.  
  3.  
  4.  
  5.         private final int SPLASH_DISPLAY_LENGTH = 5000;
  6.  
  7.        
  8.  
  9.         /** called when the activity is first created */
  10.  
  11.         @Override
  12.  
  13.         public void onCreate( Bundle icicle ){
  14.  
  15.                 super.onCreate( icicle );
  16.  
  17.                 setContentView( R.layout.splashscreen );
  18.  
  19.                
  20.  
  21.  
  22.  
  23.                 /* New Handler to start the Menu-Activity
  24.  
  25.                  * and close this splash creen after some secods
  26.  
  27.                  */
  28.  
  29.                 new Handler().postDelayed(new Runnable(){
  30.  
  31.                         @Override
  32.  
  33.                         public void run(){
  34.  
  35.                                 /*Create an Intent that will start the Menu.Activity */
  36.  
  37.                                 Intent mainIntent = new Intent( Splash.this, MainMenu.class );
  38.  
  39.                                 Splash.this.startActivity( mainIntent );
  40.  
  41.                                 Splash.this.finish();
  42.  
  43.                         }
  44.  
  45.                 }, SPLASH_DISPLAY_LENGTH );
  46.  
  47.         }
  48.  
  49. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Note, in my case, the xml file defining the splash screen is R.layout.splash screen and the class that defines my main menu is the MainMenu.class as you can see from the line

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent mainIntent = new Intent( Splash.this, MainMenu.class );
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



Cheers,
--D
rmanromga
Developer
Developer
 
Posts: 43
Joined: Thu Dec 20, 2007 6:21 am
Location: Baltimore, MD USA

Postby and.modi » Fri Nov 14, 2008 4:43 am

Thanks,
It worked perfectly.
But can you tell me what is wrong in my method?
If u can inform me that, it will be of great help me to understand.

Cheers,---- :D
and.modi
Junior Developer
Junior Developer
 
Posts: 14
Joined: Sat Jul 26, 2008 9:17 am

Postby rmanromga » Fri Nov 14, 2008 5:01 am

I'm glad it worked..

As for your why your method did not work, what is the xml file defining your splash screen? I dont see you settingContentView on this splash view?? It seems like you call

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  setContentView(R.layout.main);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Then you send your thread to sleep for 2000ms, then right after that you start the Activity with the main menu Intent. Thats why I'm wondering where your call to your splash screen is. Using a Handler like what I did is the best way because you schedule on the message queue of the current thread and you can schedule an action on the message queue and you can specify how long to wait in the message queue before the runnable that calls the startActivity on the MainMienu Intent waits. Thus your splash screen just waits.......Tale a look at the API docs for Handler...

ps. When you post your code, use the "java" tags to surround any code that you post so that your code is formated in the forum and is easier to read.. its painful trying to read your code :-)
rmanromga
Developer
Developer
 
Posts: 43
Joined: Thu Dec 20, 2007 6:21 am
Location: Baltimore, MD USA

Postby and.modi » Fri Nov 14, 2008 5:58 am

Thanks for your coments. :lol:
Now I understnad the problem lil bit..
And I will pu java tag for sure from net time...

Thanks for the Tip.. 8)
and.modi
Junior Developer
Junior Developer
 
Posts: 14
Joined: Sat Jul 26, 2008 9:17 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 9 guests