[align=center]Alternative which does not start another Activity
What you learn: You will learn how to create a simple splashscreen for your application:
Difficulty: 0.5 of 5
What it will look like: [align=center]Example from my AndNav! -Application
[/align]
Description: The code is somewhat self-expressive. Dont forget to add this new Activity in the AndroidManifest.xml
"/res/layout/splashscreen.xml":
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <ImageView
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:scaleType="fitCenter"
- android:src="@drawable/place_your_splashimage_here"
- />
- </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
"/src/your_package_structure/Splash.java":
Using java Syntax Highlighting
- package org.anddev.android.andnav;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.os.Handler;
- public class Splash extends Activity {
- // ===========================================================
- // Fields
- // ===========================================================
- private final int SPLASH_DISPLAY_LENGHT = 1000;
- // ===========================================================
- // "Constructors"
- // ===========================================================
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(R.layout.splashscreen);
- /* New Handler to start the Menu-Activity
- * and close this Splash-Screen after some seconds.*/
- new Handler().postDelayed(new Runnable(){
- @Override
- public void run() {
- /* Create an Intent that will start the Menu-Activity. */
- Intent mainIntent = new Intent(Splash.this,Menu.class);
- Splash.this.startActivity(mainIntent);
- Splash.this.finish();
- }
- }, SPLASH_DISPLAY_LENGHT);
- }
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
[align=center]Thats it
[/align]
Regards,
plusminus







