Tuesday, 15 June 2010

install - How to add a first-load screen in Android? -



install - How to add a first-load screen in Android? -

how add together splash screen displayed only when user starts app first time after installing. something how-to-use guide.

first need define splash screen in layout.xml file

<?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 id="@+id/splashscreen" android:layout_width="wrap_content" android:layout_height="fill_parent" android:src="@drawable/splash" android:layout_gravity="center"/> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="hello world, splash"/> </linearlayout>

and activity see if it's first time run:

public class firsttimerun extends activity { public static string prefname = "random"; sharedpreferences prefs; @override protected void oncreate(bundle arg0) { // todo auto-generated method stub super.oncreate(arg0); prefs = getsharedpreferences(prefname, mode_private); if (prefs.getstring("firsttime", true) == true){ intent = new intent(firsttimerun.this, splash.class); startactivity(i); }else{ //start activity } }

splash class:

import android.app.activity; import android.content.intent; import android.os.bundle; import android.os.handler; public class splash extends activity { private final int splash_display_length = 1000; public static string prefname = "random"; sharedpreferences prefs; /** called when activity first created. */ @override public void oncreate(bundle icicle) { super.oncreate(icicle); setcontentview(r.layout.splashscreen); prefs = getsharedpreferences(prefname, mode_private); editor edito = prefs.edit(); edito.putstring("firsttime", false); edito.commit(); /* new handler start menu-activity * , close splash-screen after seconds.*/ new handler().postdelayed(new runnable(){ @override public void run() { /* create intent start menu-activity. */ intent mainintent = new intent(splash.this,menu.class); splash.this.startactivity(mainintent); splash.this.finish(); } }, splash_display_length); } }

thats ;)

android install splash-screen

No comments:

Post a Comment