Simple splash screen - Alternative

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

Postby jpe30 » Tue Jun 09, 2009 3:14 pm

So this method works, however, it does not remove the splash screen after the time limit. Any thoughts as to why that is?
jpe30
Freshman
Freshman
 
Posts: 4
Joined: Mon Jun 08, 2009 11:24 pm

Top

Postby IG88 » Thu Sep 10, 2009 8:22 pm

This is a nice tutorial-- thank-you for taking the time to create/ post it :wink:

It is exciting to run this in the emulator and have my chosen image appear; beyond that I am learning more about Android/Java which is great.

One problem though if anyone could shed some light: upon boot all goes well then there is an error message of "Force Close", an ominous sign we all hate to see I'm sure. :o

From the beginning I have worried about Force Close issues and want to learn how to address them in general (and for this specific case).

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


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


Thank-you in advance for any help or direction,
[font=Arial Black]IG88[/font]
Attachments
safe_wheel2.gif
Image used for splash.
(61.15 KiB) Downloaded 240 times
User avatar
IG88
Freshman
Freshman
 
Posts: 4
Joined: Tue Sep 08, 2009 7:36 pm
Location: New York City

Postby IG88 » Thu Sep 10, 2009 10:26 pm

After looking at my problem I think the Force Close is coming from that the image loads and runs:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  private final int SPLASH_DISPLAY_LENGTH = 1000;
  3.  
  4.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


It then closes after "1000" as the program is done and cannot proceed.

I altered the code simply to:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  private final int SPLASH_DISPLAY_LENGTH = 5000;
  3.  
  4.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


The code still force closed after a longer emulator display of the image.

I believe this is the reason for the force closing, that is, the program is complete.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. splash1.this.finish();
  3.  
  4.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4



I am not sure if that is correct :?:

[font=Arial Black]IG88[/font]
User avatar
IG88
Freshman
Freshman
 
Posts: 4
Joined: Tue Sep 08, 2009 7:36 pm
Location: New York City

Want to send my application in Icon Tray....

Postby Pushpalata » Sat Oct 03, 2009 6:43 am

Hello,
I want to minimize my running application.....can I place it in notification statusbar?
In my applications home tab i hv created a button 'Minimize' and on the click event of this button I wish to send my applications name in icon tray, in running state.....?
Is it possible...?
plz reply !
PUSHPALATA
Pushpalata
Freshman
Freshman
 
Posts: 6
Joined: Wed Sep 23, 2009 5:12 pm

Re: Help Please

Postby crazytickler » Tue Dec 01, 2009 4:14 pm

Klethron wrote: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.005 seconds, using GeSHi 1.0.8.4
crazytickler
Freshman
Freshman
 
Posts: 2
Joined: Tue Dec 01, 2009 4:11 pm

i tried but

Postby crazytickler » Wed Dec 02, 2009 11:27 am

I am trying this code, but it is a little confusing. Why is the name .Menu and what should i give string value as app_string_menu

i 'd have to add a string app_name_menu in strings, rght ?
crazytickler
Freshman
Freshman
 
Posts: 2
Joined: Tue Dec 01, 2009 4:11 pm

Top

Postby kristophercroteau » Fri Jan 08, 2010 4:05 pm

OK i see people mention it crashes on them but i have not seen anyone say they solved it (with the modified code)

I can get my splash image to appear, but upon its call to close it get an error:
"The application APPLICATION NAME (process PACKAGE NAME) has stopped unexpectedly. Please try again. with a force close button.

Here is my code:
Manifest
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.      package="org.vampresearch.android.Hello_Android"
  6.  
  7.      android:versionCode="1"
  8.  
  9.      android:versionName="1.0">
  10.  
  11.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  12.  
  13.  
  14.  
  15.         <activity android:name=".Splash">
  16.  
  17.             <intent-filter>
  18.  
  19.                 <action android:name="android.intent.action.MAIN" />
  20.  
  21.                 <category android:name="android.intent.category.LAUNCHER" />
  22.  
  23.             </intent-filter>
  24.  
  25.         </activity>
  26.  
  27.        
  28.  
  29.         <activity android:name=".Hello_Android"
  30.  
  31.                  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.  
  44.  
  45.     </application>
  46.  
  47.     <uses-sdk android:minSdkVersion="3" />
  48.  
  49.  
  50.  
  51. </manifest>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


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


Any ideas?
kristophercroteau
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Jan 08, 2010 3:45 pm
Location: Vermont

Postby artfuldodger » Fri Jan 15, 2010 5:55 pm

You have the following activities defined:

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


but then here:

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


you are telling it to start an Intent with the explicit target of Menu.class. Do you have an activity in Menu.java? It doesn't look like it.
artfuldodger
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Jan 15, 2010 5:47 pm
Location: Tulsa, OK

Postby izu516 » Sun Jan 17, 2010 6:01 am

Easiest thing to do?

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


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


And make sure you have created a Java file called Hello_Android ! With all the proper activity stuff in it (ie. your program's executable code)

The reason for you peoples' force closures is that you never created an activity that would launch when the splashcreen was finished, so as soon as the time was up and it tried to switch to your activity, it couldn't because you had none and so it crashed
Go anddev!
izu516
Developer
Developer
 
Posts: 27
Joined: Sat Nov 14, 2009 2:18 am
Location: US

Dinamic splash time, splash inside TabHost

Postby enez » Thu Jan 21, 2010 7:01 pm

Hi! I have two questions about splash.

-Is there any possibility to set splash time dynamically. For example I want to display splash screen until another activity finish their back end processing.
-How to work with splash screen inside Tabhost. For example when user click on some tab, I want to display splash screen but like in first question.

I will appreciate any link or example.
My apologizes if I miss something until now...
enez
Freshman
Freshman
 
Posts: 4
Joined: Thu Jan 21, 2010 6:39 pm

Happens only Once

Postby kdiddy » Tue Mar 09, 2010 10:37 pm

Thanks for the code. It works great except it only works once. If I close my app..(even kill it in my task manager) when I reload the app the splash screen doesn't show. Is there any way to reset the Handler.

Instead of my splash screen loading it loads my next screen which is the apps main screen. I have the Splash screen as the launcher but again it only happens the first time I load the app.

Thanks,
K
Diddy
kdiddy
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Apr 01, 2009 2:30 am

Postby sheeeng » Wed Mar 10, 2010 5:38 am

Thanks for the fine tutorial!

Same experience for me too. I can get my splash image to appear, but upon its call to close it get an error:
"The application APPLICATION NAME (process PACKAGE NAME) has stopped unexpectedly. Please try again. with a force close button.

Does anyone know how to solve it?
Regards,
Leonard
sheeeng
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Mar 10, 2010 5:33 am
Location: Kuala Lumpur, Malaysia

Postby sblantipodi » Sat Mar 27, 2010 1:04 am

I'm not able to connect this splash with an activity.
is there someone who can post an example of this splash screen that displays an hello world after 5 seconds please?

thanks.
sblantipodi
Senior Developer
Senior Developer
 
Posts: 122
Joined: Fri Mar 26, 2010 1:41 pm

Postby m.francia » Tue Mar 30, 2010 4:46 pm

it works great! thanks plusminus

I start this splashScreen from my app's main activity and simply use this OnCreate() modified version to stop this activity and make it disappear:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public void onCreate(Bundle icicle)
  3.  
  4.      {
  5.  
  6.           super.onCreate(icicle);
  7.  
  8.           setContentView(R.layout.splash);
  9.  
  10.           new Handler().postDelayed(new Runnable(){public void run(){SplashScreen.this.finish();}}, SPLASH_LENGHT);
  11.  
  12.      }
  13.  
  14.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
Image
User avatar
m.francia
Freshman
Freshman
 
Posts: 5
Joined: Wed Mar 24, 2010 2:11 pm

Hello

Postby pedroteixeira07 » Wed Apr 21, 2010 4:55 pm

Hi, I have everything ok, no errors at all. But the splash simple doesn't appear.. any suggestions ?

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


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

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests