I want to show a splashScreen on my app firstly for few seconds and then load all my threads data using timer in java, then how should i do it.
Asked
Active
Viewed 313 times
0
-
in main method, you need to create a borderless JFrame, that shows your splash screen, then sleep for some second and rest of the work – Jul 07 '13 at 13:58
-
Use the `SplashScreen` class as discussed [here](http://stackoverflow.com/a/6401999/418556). – Andrew Thompson Jul 07 '13 at 14:01
2 Answers
0
Add Splash Screen Activity to your Project... now replace the SplashScree.java file code as :
package samples.splash.screen;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
/**
* Splash screen activity
*
* @author Catalin Prata
*/
public class SplashScreen extends Activity {
// used to know if the back button was pressed in the splash screen activity and avoid opening the next activity
private boolean mIsBackButtonPressed;
private static final int SPLASH_DURATION = 2000; // 2 seconds
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
Handler handler = new Handler();
// run a thread after 2 seconds to start the home screen
handler.postDelayed(new Runnable() {
@Override
public void run() {
// make sure we close the splash screen so the user won't come back when it presses back key
finish();
if (!mIsBackButtonPressed) {
// start the home screen if the back button wasn't pressed already
Intent intent = new Intent(SplashScreen.this, Home.class);
SplashScreen.this.startActivity(intent);
}
}
}, SPLASH_DURATION); // time in milliseconds (1 second = 1000 milliseconds) until the run() method will be called
}
@Override
public void onBackPressed() {
// set the flag to true so the next activity won't start up
mIsBackButtonPressed = true;
super.onBackPressed();
}
}
And the splash_screen xml looks like this: where you should have any image in your drawables named : "splash_screen"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/splash_screen"/>
Now make your Splash Screen a Launcher Activity in Manifest File to make it a startup Activity.. And in order to get the title bar of the application down, just add he activity in your manifest and add the theme as you can see below:
<activity android:name=".SplashScreen" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN">
<category android:name="android.intent.category.LAUNCHER">
</category></action></intent-filter>
</activity>

Umais Gillani
- 608
- 4
- 9