Simple splash screen - Alternative

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

Postby trusk » Thu Apr 22, 2010 5:14 pm

In my project I have another class, the Hello_Android.class file. How do I link it, so the splash dissapears and my app appears?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package ex.splash;
  2.  
  3.  
  4.  
  5.  
  6.  
  7. import android.app.Activity;
  8.  
  9. import android.content.Intent;
  10.  
  11. import android.os.Bundle;
  12.  
  13. import android.os.Handler;
  14.  
  15.  
  16.  
  17. public class Splashscreen extends Activity {
  18.  
  19.  
  20.  
  21.  
  22.  
  23.         private final int SPLASH_DISPLAY_LENGHT = 3000;
  24.  
  25.  
  26.  
  27.         @Override
  28.  
  29.         public void onCreate(Bundle icicle) {
  30.  
  31.                 super.onCreate(icicle);
  32.  
  33.                 setContentView(R.layout.main);
  34.  
  35.  
  36.  
  37.          
  38.  
  39.                 new Handler().postDelayed(new Runnable(){
  40.  
  41.                         @Override
  42.  
  43.                         public void run() {
  44.  
  45.        
  46.  
  47.                                 Intent mainIntent = new Intent(Splashscreen.this,Splashscreen.class);
  48.  
  49.                                 Splashscreen.this.startActivity(mainIntent);
  50.  
  51.                                 Splashscreen.this.finish();
  52.  
  53.                         }
  54.  
  55.                 }, SPLASH_DISPLAY_LENGHT);
  56.  
  57.                
  58.  
  59.         }
  60.  
  61. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


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" android:layout_width="fill_parent"
  6.  
  7.         android:layout_height="fill_parent">
  8.  
  9.         <ImageView android:layout_width="fill_parent"
  10.  
  11.                 android:layout_height="fill_parent" android:scaleType="fitCenter"
  12.  
  13.                 android:src="@drawable/truska" />
  14.  
  15. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


With this code, the app keeps popping up from the home screen of the emulator. Is it normal?
trusk
Freshman
Freshman
 
Posts: 4
Joined: Fri Apr 16, 2010 7:31 pm

Top

Postby pedroteixeira07 » Fri Apr 23, 2010 10:32 am

You should chande your java here :

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


to:

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


Also you have to insert the new activity in the android manifest like this for ex:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.         <activity android:name=".Splashscreen">
  3.  
  4.                  <intent-filter>
  5.  
  6.                         <action android:name="android.intent.action.MAIN" />
  7.  
  8.                 <category android:name="android.intent.category.LAUNCHER" />      
  9.  
  10.             </intent-filter>
  11.  
  12.         </activity>
  13.  
  14.        
  15.  
  16.         <activity android:name=".Hello_Android" android:label="@string/app_name">
  17.  
  18.             <intent-filter>
  19.  
  20.                 <action android:name="android.intent.action.DEFAULT" />
  21.  
  22.                 <category android:name="android.intent.category.VIEW" />
  23.  
  24.             </intent-filter>
  25.  
  26.         </activity>    
  27.  
  28.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


It should work now!
pedroteixeira07
Experienced Developer
Experienced Developer
 
Posts: 74
Joined: Sun Oct 18, 2009 6:06 pm
Location: Funchal

Postby trusk » Fri Apr 23, 2010 11:51 am

I get the "force close" error.... Any thaughts?
trusk
Freshman
Freshman
 
Posts: 4
Joined: Fri Apr 16, 2010 7:31 pm

Postby pskink » Fri Apr 23, 2010 11:57 am

trusk wrote:I get the "force close" error.... Any thaughts?


without any traceback, no
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby trusk » Fri Apr 23, 2010 8:14 pm

I did what everything that you said

My xml looks like this
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" android:layout_width="fill_parent"
  6.  
  7.         android:layout_height="fill_parent">
  8.  
  9.         <ImageView android:layout_width="fill_parent"
  10.  
  11.                 android:layout_height="fill_parent" android:scaleType="fitCenter"
  12.  
  13.                 android:src="@drawable/truska" />
  14.  
  15.  
  16.  
  17.         <activity android:name=".Splashscreen">
  18.  
  19.                 <intent-filter>
  20.  
  21.                         <action android:name="android.intent.action.MAIN" />
  22.  
  23.                         <category android:name="android.intent.category.LAUNCHER" />
  24.  
  25.                 </intent-filter>
  26.  
  27.         </activity>
  28.  
  29.  
  30.  
  31.         <activity android:name=".Hello_Android" android:label="@string/app_name">
  32.  
  33.                 <intent-filter>
  34.  
  35.                         <action android:name="android.intent.action.DEFAULT" />
  36.  
  37.                         <category android:name="android.intent.category.VIEW" />
  38.  
  39.                 </intent-filter>
  40.  
  41.         </activity>
  42.  
  43. </LinearLayout>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
trusk
Freshman
Freshman
 
Posts: 4
Joined: Fri Apr 16, 2010 7:31 pm

Re: Simple splash screen - Alternative

Postby jon.dproj » Sat Jun 05, 2010 3:05 am

pedroteixeira07 wrote: Also you have to insert the new activity in the android manifest like this for ex:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.         <activity android:name=".Splashscreen">
  2.                  <intent-filter>
  3.                         <action android:name="android.intent.action.MAIN" />
  4.                 <category android:name="android.intent.category.LAUNCHER" />      
  5.             </intent-filter>
  6.         </activity>
  7.        
  8.         <activity android:name=".Hello_Android" android:label="@string/app_name">
  9.             <intent-filter>
  10.                 <action android:name="android.intent.action.DEFAULT" />
  11.                 <category android:name="android.intent.category.VIEW" />
  12.             </intent-filter>
  13.         </activity>    
  14.  
  15.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


It should work now!


I had the issue of the splash simply not displaying, turned out to be the way I had added it to the manifest. Following the above advice solved it.
jon.dproj
Freshman
Freshman
 
Posts: 3
Joined: Sat Jun 05, 2010 2:54 am

Top

Re: Simple splash screen - Alternative

Postby anique » Mon Jun 07, 2010 10:39 am

Another thing which can make the splash screen better is to not use the title bar.
Add the following line for your activity in the manifest:
Code: Select all
android:theme="@android:style/Theme.NoTitleBar"
anique
Freshman
Freshman
 
Posts: 3
Joined: Sun May 09, 2010 12:22 pm

Re: Simple splash screen - Alternative

Postby hassanm » Wed Aug 18, 2010 12:46 am

I get the unexpected close also, here is my manifest

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.app.dave"
  4.      android:versionCode="1"
  5.      android:versionName="1.0">
  6.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  7.    
  8.     <activity android:name=".splash"
  9.    android:theme="@android:style/Theme.NoTitleBar">
  10.                                  
  11.                   <intent-filter>
  12.                   <action android:name="android.intent.action.MAIN" />
  13.                   <category android:name="android.intent.category.LAUNCHER"/>
  14.                   </intent-filter>
  15.                   </activity>
  16.                  
  17.         <activity android:name=".Main"
  18.                  android:label="@string/app_name">
  19.             <intent-filter>
  20.                 <action android:name="android.intent.action.DEFAULT" />
  21.                 <category android:name="android.intent.category.VIEW" />
  22.             </intent-filter>
  23.         </activity>
  24.  
  25.     </application>
  26.     <uses-sdk android:minSdkVersion="4" />
  27.  
  28. </manifest>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


layout:


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


splash class
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.app.dave;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.os.Handler;
  7.  
  8. public class splash extends Activity {
  9.        
  10.         private final int SPLASH_DISPLAY_LENGTH= 3000;
  11.     /** Called when the activity is first created. */
  12.     @Override
  13.     public void onCreate(Bundle icycle) {
  14.         super.onCreate(icycle);
  15.         setContentView(R.layout.main);
  16.        
  17.         new Handler().postDelayed(new Runnable(){
  18.                 @Override
  19.                
  20.                 public void run(){
  21.                         Intent mainIntent= new Intent(splash.this,Main.class);
  22.                         splash.this.startActivity(mainIntent);
  23.                         splash.this.finish();
  24.                        
  25.                 }
  26.         }, SPLASH_DISPLAY_LENGTH);
  27.        
  28.     }
  29. }
  30.        
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


main class
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.app.dave;
  2.  
  3. import android.app.Activity;
  4. import android.widget.TextView;
  5.  
  6. import android.os.Bundle;
  7.  
  8. public class Main extends Activity {
  9.        
  10.     /** Called when the activity is first created. */
  11.     @Override
  12.     public void onCreate(Bundle savedInstanceState) {
  13.         TextView tv =new TextView(this);
  14.         tv.setText("Hello With SplashScreen");
  15.         setContentView(tv);
  16.        
  17.     }
  18. }        
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
hassanm
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Aug 18, 2010 12:42 am

Re: Simple splash screen - Alternative

Postby zarahjutz » Wed Sep 08, 2010 4:06 am

@hassanm: Perhaps you can paste a trace from LogCat to show the reason for the force close.
zarahjutz
Freshman
Freshman
 
Posts: 3
Joined: Tue Sep 07, 2010 10:36 am

Re: Simple splash screen - Alternative

Postby edreamz » Wed Sep 08, 2010 11:20 pm

I am getting the following error in the Manifest XML file.
Class com.felix.splash.menu does not exist

<activity android:label="@string/app_name" android:name=".Menu">
User avatar
edreamz
Junior Developer
Junior Developer
 
Posts: 18
Joined: Fri Aug 06, 2010 2:29 am
Location: U.S

Re: Simple splash screen - Alternative

Postby edreamz » Thu Sep 09, 2010 5:11 pm

edreamz wrote:I am getting the following error in the Manifest XML file.
Class com.felix.splash.menu does not exist

<activity android:label="@string/app_name" android:name=".Menu">



Renamed my parent activity to Main and poof the error disappeared.
Thanks for the tutorial, I am learning a lot from these.

My working code for reference:

main.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.felix.splash;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5.  
  6. public class Main extends Activity {
  7.  
  8.         @Override
  9.         protected void onCreate(Bundle savedInstanceState) {
  10.                 // TODO Auto-generated method stub
  11.                 super.onCreate(savedInstanceState);
  12.         setContentView(R.layout.main);
  13.  
  14.         }
  15.  
  16. }
  17.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


SplashScreen.Java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.felix.splash;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.os.Handler;
  7.  
  8. public class SplashScreen extends Activity {
  9.         private final int SPLASH_DISPLAY_LENGTH = 5000;
  10.         /** Called when the activity is first created. */
  11.         @Override
  12.         public void onCreate(Bundle savedInstanceState) {
  13.                 super.onCreate(savedInstanceState);
  14.                 setContentView(R.layout.splash);
  15.  
  16.                 new Handler().postDelayed(new Runnable(){
  17.                         //@Override
  18.                         public void run() {
  19.                                 Intent mainIntent = new Intent(SplashScreen.this,Main.class);
  20.                                 SplashScreen.this.startActivity(mainIntent);
  21.                                 SplashScreen.this.finish();
  22.                         }
  23.                 }, SPLASH_DISPLAY_LENGTH);
  24.         }
  25. }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4

manifest xml
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.felix.splash" android:versionCode="1" android:versionName="1.0">
  4.         <application android:icon="@drawable/icon" android:label="@string/app_name">
  5.                 <activity android:name=".SplashScreen" android:label="@string/app_name">
  6.                         <intent-filter>
  7.                                 <action android:name="android.intent.action.MAIN" />
  8.                                 <category android:name="android.intent.category.LAUNCHER" />
  9.                         </intent-filter>
  10.                 </activity>
  11.                 <activity android:label="@string/app_name" android:name=".Main">
  12.  
  13.                         <intent-filter>
  14.                                 <action android:name="android.intent.action.DEFAULT" />
  15.                                 <category android:name="android.intent.category.VIEW" />
  16.                         </intent-filter>
  17.                 </activity>
  18.         </application>
  19. </manifest>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
User avatar
edreamz
Junior Developer
Junior Developer
 
Posts: 18
Joined: Fri Aug 06, 2010 2:29 am
Location: U.S

Re: Simple splash screen - Alternative

Postby erwan.pinault » Fri Sep 24, 2010 11:43 am

Like other people I have a strange situation.
When I first launched my application the splashscreen appears and my mainactivity appears next. But when I close the mainactivity and when i launch the application by using the launcher (long press on home button :-D) the splashscreen doesn't appear but my mainactivty does.

This is the code for my activities:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <activity
  2.         android:launchMode="singleInstance"
  3.         android:name="SplashScreenActivity"
  4.         android:theme="@android:style/Theme.NoTitleBar">
  5.         <intent-filter>
  6.                 <action
  7.                         android:name="android.intent.action.DEFAULT" />
  8.                 <action
  9.                         android:name="android.intent.action.MAIN" />
  10.                 <category
  11.                         android:name="android.intent.category.LAUNCHER" />
  12.                 <category
  13.                         android:name="android.intent.category.HOME" />
  14.         </intent-filter>
  15. </activity>
  16. <activity
  17.         android:launchMode="singleTask"
  18.         android:name="MainActivity"
  19.         android:theme="@android:style/Theme.NoTitleBar">
  20. </activity>
  21.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
erwan.pinault
Freshman
Freshman
 
Posts: 3
Joined: Thu Aug 05, 2010 3:29 pm

Re: Simple splash screen - Alternative

Postby wahid2oo9 » Tue Feb 08, 2011 10:38 am

how do i make a splash screen that goes to a page, but if a button is clicked inside the splash screen it will go to another page and not the page its meant to go after splash screen.

help please?
wahid2oo9
Developer
Developer
 
Posts: 36
Joined: Fri Dec 31, 2010 7:07 am

Re: Simple splash screen - Alternative

Postby cpedersen » Wed Apr 20, 2011 12:09 pm

I made a splash screen mysel, but forgot the AndroidManifest.xml, thanks you alot (:
cpedersen
Freshman
Freshman
 
Posts: 2
Joined: Wed Apr 20, 2011 8:51 am
Location: Denmark

Re: Simple splash screen - Alternative

Postby la3bna » Tue May 03, 2011 12:51 pm

I used the code from the first post here but when i run the app on my phone I only got the splash screen on first run.
What have i done wrong?

The app also keeps running after i exit (in my mind at least)
.
la3bna
Experienced Developer
Experienced Developer
 
Posts: 72
Joined: Wed Mar 30, 2011 5:49 am
Location: Stavern, Norway

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests