java - How to get time for splashscreen -
how time splashcreen? want add 15 second time? how can integrate code? example, direct activity after 15 seconds.
package com.trees.activities; import android.app.activity; import android.content.intent; import android.content.sharedpreferences; import android.os.bundle; public class mainslider extends activity{ @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); sharedpreferences settings=getsharedpreferences("prefs",0); boolean firstrun=settings.getboolean("firstrun",false); if(firstrun==false)//if running first time //splash load first time { sharedpreferences.editor editor=settings.edit(); editor.putboolean("firstrun",true); editor.commit(); intent i=new intent(mainslider.this,materialintro.class); startactivity(i); finish(); } else { intent a=new intent(mainslider.this,mainactivity.class); startactivity(a); finish(); } } }
how to: simple spash screen
first need define spash 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 android: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:
import android.app.activity; import android.content.intent; import android.os.bundle; import android.os.handler; public class splash extends activity { /** duration of wait **/ private final int splash_display_length = 1000; /** called when activity first created. */ @override public void oncreate(bundle icicle) { super.oncreate(icicle); setcontentview(r.layout.splashscreen); /* 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); } }
Comments
Post a Comment