Simple splash screen - Alternative

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Simple splash screen - Alternative

Postby plusminus » Fri Feb 08, 2008 3:22 pm

[align=center]Simple splash screen - Alternative[/align]
[align=center]Alternative which does not start another Activity :arrow: :src: here.[/align]

What you learn: You will learn how to create a simple splashscreen for your application:

Difficulty: 0.5 of 5 :)

:idea: Questions/Problems: Simply post below...

What it will look like: [align=center]Example from my AndNav! -Application
Image[/align]

Description: The code is somewhat self-expressive. Dont forget to add this new Activity in the AndroidManifest.xml :!:

"/res/layout/splashscreen.xml":
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    android:orientation="vertical"
  6.  
  7.    android:layout_width="fill_parent"
  8.  
  9.    android:layout_height="fill_parent"
  10.  
  11.    >
  12.  
  13.     <ImageView
  14.  
  15.         android:layout_width="fill_parent"
  16.  
  17.         android:layout_height="fill_parent"
  18.  
  19.         android:scaleType="fitCenter"
  20.  
  21.         android:src="@drawable/place_your_splashimage_here"
  22.  
  23.         />
  24.  
  25. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


"/src/your_package_structure/Splash.java":
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.anddev.android.andnav;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.content.Intent;
  8.  
  9. import android.os.Bundle;
  10.  
  11. import android.os.Handler;
  12.  
  13.  
  14.  
  15. public class Splash extends Activity {
  16.  
  17.  
  18.  
  19.         // ===========================================================
  20.  
  21.         // Fields
  22.  
  23.         // ===========================================================
  24.  
  25.        
  26.  
  27.         private final int SPLASH_DISPLAY_LENGHT = 1000;
  28.  
  29.  
  30.  
  31.         // ===========================================================
  32.  
  33.         // "Constructors"
  34.  
  35.         // ===========================================================
  36.  
  37.  
  38.  
  39.         /** Called when the activity is first created. */
  40.  
  41.         @Override
  42.  
  43.         public void onCreate(Bundle icicle) {
  44.  
  45.                 super.onCreate(icicle);
  46.  
  47.                 setContentView(R.layout.splashscreen);
  48.  
  49.                
  50.  
  51.                 /* New Handler to start the Menu-Activity
  52.  
  53.                  * and close this Splash-Screen after some seconds.*/
  54.  
  55.                 new Handler().postDelayed(new Runnable(){
  56.  
  57.                         @Override
  58.  
  59.                         public void run() {
  60.  
  61.                                 /* Create an Intent that will start the Menu-Activity. */
  62.  
  63.                                 Intent mainIntent = new Intent(Splash.this,Menu.class);
  64.  
  65.                                 Splash.this.startActivity(mainIntent);
  66.  
  67.                                 Splash.this.finish();
  68.  
  69.                         }
  70.  
  71.                 }, SPLASH_DISPLAY_LENGHT);
  72.  
  73.         }
  74.  
  75. }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4

[align=center]Thats it :)[/align]

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby novice » Fri Feb 15, 2008 5:45 am

Thanks for the tutorial plusminus.
I have the Splash activity in manifest file.
after the splash screen i get the error

Unable to find explicit activity class androd.view.menu

How do i add the 2nd activity to manifestfile?

thanks
wasiq
novice
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Feb 15, 2008 5:34 am

Postby plusminus » Fri Feb 15, 2008 10:48 am

Hello novice,

in SDK-version m5 you'll write:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.         <activity android:name=".Menu" android:label="@string/app_name_menu">
  2.  
  3.             <intent-filter>
  4.  
  5.                 <action android:name="android.intent.action.DEFAULT" />
  6.  
  7.                 <category android:name="android.intent.category.VIEW" />
  8.  
  9.             </intent-filter>
  10.  
  11.         </activity>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

error for Run() method

Postby neel » Sun Feb 17, 2008 4:53 am

i followed ur method and get the following error

The method run() of type new Runnable(){} must override a superclass method
neel
Developer
Developer
 
Posts: 31
Joined: Fri Feb 15, 2008 5:09 am
Location: San Jose

Postby plusminus » Sun Feb 17, 2008 12:44 pm

Hello neel,

you've got two possibilities:
a.) simply Comment the @Override-Annotation out
b.) Update to JDK 1.6 (preferred)

This happens because the JDK 1.5, you are probably running, does accept @Override-Annotation only for overridden methods of Super-Classes and not for overriding functions of Interfaces we are implementing here.

On JDK 1.6 this Annotation is possible. :roll:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby neel » Sun Feb 17, 2008 5:57 pm

i commented the annotation and it works......thanks
neel
Developer
Developer
 
Posts: 31
Joined: Fri Feb 15, 2008 5:09 am
Location: San Jose

Top

Postby shareme » Tue Nov 11, 2008 1:28 pm

missing one import, this one:

import android.view.Menu;
shareme
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sun Nov 09, 2008 1:54 pm
Location: SE ChicagoLand

Postby sainath » Thu Feb 26, 2009 10:02 am

Hi,

The above Example works perfectly with Android SDK 1.0_r2.
Regards
Sainath
User avatar
sainath
Freshman
Freshman
 
Posts: 4
Joined: Thu Feb 26, 2009 5:35 am

Something is off, it's most likely me.

Postby Klethron » Fri Feb 27, 2009 8:30 pm

Hey Gang,

Using the above tutorial I cannot seem to get the splash screen to load, maybe it's my AndroidManifest.xml file, I'm not quite sure what I am missing. Maybe one of you guys can point me in the right direction. Below is my manifest file.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.      package="com.android.kbennion"
  7.  
  8.      android:versionCode="1"
  9.  
  10.      android:versionName="1.0.0">
  11.  
  12.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  13.  
  14.         <activity android:name=".kbennion" android:label="@string/app_name" android:screenOrientation="portrait">              
  15.  
  16.             <intent-filter>
  17.  
  18.                 <action android:name="android.intent.action." />
  19.  
  20.                 <category android:name="android.intent.category.VIEW" />
  21.  
  22.             </intent-filter>
  23.  
  24.             <intent-filter>
  25.  
  26.                 <action android:name="android.intent.action.MAIN" />
  27.  
  28.                 <category android:name="android.intent.category.LAUNCHER" />
  29.  
  30.             </intent-filter>
  31.  
  32.         </activity>
  33.  
  34.     </application>
  35.  
  36. </manifest>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
Klethron
Freshman
Freshman
 
Posts: 6
Joined: Thu Feb 05, 2009 5:21 pm

Postby kali » Wed Mar 04, 2009 7:22 am

hai klethron
y should do as under in your androidmanifest.xml
<activity android:name=".Menu" android:label="@string/app_name_menu">
<intent-filter>
<action android:name="android.intent.action.DEFAULT" />
<category android:name="android.intent.category.VIEW" />
</intent-filter>
</activity>

this will include second activity to be displayed
kali
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Tue Jan 27, 2009 1:31 pm

Postby reynolds » Fri Mar 06, 2009 6:44 am

Hi guys,

I was trying to run this splash screen as well.

The screen shows, but it keeps crashing.
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.      package="com.splashScreen"
  7.  
  8.      android:versionCode="1"
  9.  
  10.      android:versionName="1.0.0">
  11.  
  12.     <application android:icon="@drawable/travelmanagement" android:label="@string/app_name">
  13.  
  14.         <activity android:name=".SplashScreen"
  15.  
  16.                  android:label="@string/app_name" android:icon="@drawable/travelmanagement" android:finishOnTaskLaunch="true" android:launchMode="standard">
  17.  
  18.             <intent-filter>
  19.  
  20.                 <action android:name="android.intent.action.MAIN" />
  21.  
  22.                 <category android:name="android.intent.category.LAUNCHER" />
  23.  
  24.             </intent-filter>
  25.  
  26.         </activity>
  27.  
  28. </application>
  29.  
  30. </manifest>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4

So I added the said activity.

But when I tried to add the androidmanifest.xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.      package="com.splashScreen"
  7.  
  8.      android:versionCode="1"
  9.  
  10.      android:versionName="1.0.0">
  11.  
  12.     <application android:icon="@drawable/travelmanagement" android:label="@string/app_name">
  13.  
  14.         <activity android:name=".SplashScreen"
  15.  
  16.                  android:label="@string/app_name" android:icon="@drawable/travelmanagement" android:finishOnTaskLaunch="true" android:launchMode="standard">
  17.  
  18.             <intent-filter>
  19.  
  20.                 <action android:name="android.intent.action.MAIN" />
  21.  
  22.                 <category android:name="android.intent.category.LAUNCHER" />
  23.  
  24.             </intent-filter>
  25.  
  26.         </activity>
  27.  
  28.                 <activity android:name=".Menu" android:label="@string/app_name_menu">
  29.  
  30.                         <intent-filter>
  31.  
  32.                                 <action android:name="android.intent.action.DEFAULT" />
  33.  
  34.                                 <category android:name="android.intent.category.VIEW" />
  35.  
  36.                         </intent-filter>
  37.  
  38.                 </activity>    
  39.  
  40. </application>
  41.  
  42.  
  43.  
  44.  
  45.  
  46. </manifest>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4

It wont compile at all.
I get this error from within eclipse IDE:

Multiple annotations found at this line:
- Class com.splashScreen.Menu does not exist
- ERROR Error: No resource found that matches the given name (at 'label' with value '@string/
app_name_menu').
reynolds
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Mar 06, 2009 6:13 am
Location: Makati Philippines

Help Please

Postby Klethron » Tue Apr 07, 2009 3:40 am

Here's what I am having a hard time with so please forgive me if it sound completely noobish.

I have a application_name.java and a splash.java, I have my main.xml and a splash.xml for the splashscreen. I have my androidmanifest.xml with the activities and what have you. I load the app and for some reason It crashes every single time. Do I need to merge the 2 .java files together or what in the heck am I doing wrong here?

Here is my manifest file
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.      package="com.android.MainApp"
  7.  
  8.      android:versionCode="4" android:versionName="1.5.1">
  9.  
  10.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  11.  
  12.         <activity android:name=".Splash" android:label="@string/app_name">
  13.  
  14.             <intent-filter>
  15.  
  16.                 <action android:name="android.intent.action.MAIN" />
  17.  
  18.                 <category android:name="android.intent.category.LAUNCHER" />
  19.  
  20.             </intent-filter>
  21.  
  22.         </activity>
  23.  
  24.         <activity android:name=".MainApp"
  25.  
  26.                  android:label="@string/app_name"
  27.  
  28.                  android:screenOrientation="portrait"
  29.  
  30.                  android:launchMode="standard">
  31.  
  32.             <intent-filter>
  33.  
  34.                 <action android:name="android.intent.action.DEFAULT" />
  35.  
  36.                 <category android:name="android.intent.category.VIEW" />
  37.  
  38.             </intent-filter>
  39.  
  40.         </activity>
  41.  
  42.     </application>
  43.  
  44. </manifest>
  45.  
  46.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
Klethron
Freshman
Freshman
 
Posts: 6
Joined: Thu Feb 05, 2009 5:21 pm

Re: Help Please

Postby Klethron » Tue Apr 07, 2009 4:36 am

Nevermind, I figured it out, a little caffeine and anything is possible :P

Klethron wrote:Here's what I am having a hard time with so please forgive me if it sound completely noobish.

I have a application_name.java and a splash.java, I have my main.xml and a splash.xml for the splashscreen. I have my androidmanifest.xml with the activities and what have you. I load the app and for some reason It crashes every single time. Do I need to merge the 2 .java files together or what in the heck am I doing wrong here?

Here is my manifest file
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.      package="com.android.MainApp"
  4.      android:versionCode="4" android:versionName="1.5.1">
  5.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  6.         <activity android:name=".Splash" android:label="@string/app_name">
  7.             <intent-filter>
  8.                 <action android:name="android.intent.action.MAIN" />
  9.                 <category android:name="android.intent.category.LAUNCHER" />
  10.             </intent-filter>
  11.         </activity>
  12.         <activity android:name=".MainApp"
  13.                  android:label="@string/app_name"
  14.                  android:screenOrientation="portrait"
  15.                  android:launchMode="standard">
  16.             <intent-filter>
  17.                 <action android:name="android.intent.action.DEFAULT" />
  18.                 <category android:name="android.intent.category.VIEW" />
  19.             </intent-filter>
  20.         </activity>
  21.     </application>
  22. </manifest>
  23.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
Klethron
Freshman
Freshman
 
Posts: 6
Joined: Thu Feb 05, 2009 5:21 pm

Postby lostgame » Fri May 08, 2009 5:39 pm

How did you figure it out? I have the same problem.
lostgame
Junior Developer
Junior Developer
 
Posts: 18
Joined: Thu Apr 02, 2009 8:59 pm

Which one should I choose?

Postby sunjavaduke » Wed May 27, 2009 3:20 am

Hi plusminus,

Thanks a lot for running this community, I learned a lot.

I can implement the splash screen in your way and a.vogel's way, you know, the setVisibility way.
I have to implement a additional SplashActivity in your way, I am wondering if this will cause performance issue.
and in a.vogel's way, just set the splash part(maybe a combine ViewGroup contains both TextView and ImageView) invisible, is it a good way to let the system to collect the resource that splash part takes? I mean, if I just set the splash invisible, but the splash view will still exists, does the system garbage collector collect it immediately?

Again , thanks for your effort.
The great thing in the world is not so much where we stand, as in what direction we are moving. - by Oliver Wendell Holmes
User avatar
sunjavaduke
Freshman
Freshman
 
Posts: 5
Joined: Tue Apr 21, 2009 11:09 am
Location: Shanghai, China

Top
Next

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 6 guests