Splash screen for Android tab bar application - android

I have created the android application with tabhost. In this application, I am having the 4 tabs and each one contains their separate webview. For this application, I want to add SplashScreen for the application before the tab bar's webview is loaded. How can I achieve this?

Create a different activity to show the splash which will be your launcher activity. After launching you can start the tabhost from this activity

Try this
public class SplashScreen extends Activity {
// time for splashscreen
protected int _splashTime = 5000;
private Thread splashTread;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
final SplashScreen sPlashScreen = this;
// thread for displaying the SplashScreen
splashTread = new Thread() {
#Override
public void run() {
try {
synchronized (this) {
// wait 5 sec
wait(_splashTime);
}
} catch (InterruptedException e) {
} finally {
// Go to Main activity
Intent i = new Intent();
i.setClass(sPlashScreen, MainActivity.class);
startActivity(i);
finish();
}
}
};
splashTread.start();
}
}
Hope it helps.

Related

White color on Splash Screen

I've created a splash screen, and it works pretty fine at first, but after that, it shows me a white blank screen instead of my splash screen image file. I've no idea why that happens.
I tried to change my style.xml parent theme, but some of the themes crash my app, and only Theme.AppCompat.Light.NoActionBar works and gives me a blank white screen.
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
Splash.java
public class Splash extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread ssThread = new Thread(){
#Override
public void run() {
try {
sleep(3000);
Intent startMainScreen = new Intent(getApplicationContext(),MainActivity.class);
startActivity(startMainScreen);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
ssThread.start();
}
}
Screen sequence, thread sleep time, and everything else works fine except that the image is not showing.
In your onCreate method, you forgot to add setContentView(R.layout.splash);
You need to add setContentView to your onCreate method.
public class Splash extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
*add setContentView here after super.onCreate( )
*/
setContentView( R.layout.splash_layout);
Thread ssThread = new Thread(){
#Override
public void run() {
try {
sleep(3000);
Intent startMainScreen = new Intent(getApplicationContext(),MainActivity.class);
startActivity(startMainScreen);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
ssThread.start();
}
}
YOU MISSING setContentView(R.layout.YOUR_XML_NAME);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xxxx);
/****** Create Thread that will sleep for 3 seconds *************/
Thread background = new Thread() {
public void run() {
try {
// Thread will sleep for 3 seconds
sleep(3*1000);
// After 5 seconds redirect to another intent
Intent startMainScreen = new Intent(getApplicationContext(),MainActivity.class);
startActivity(startMainScreen);
//Remove activity
finish();
} catch (Exception e) {
}
}
};
// start thread
background.start();
}
#Override
protected void onDestroy() {
super.onDestroy();
}
}
instead of using thread and sleep function use Handler , and do some thing like this :
setContentView(R.layout.splash_screen);
int interval = 3000; // 3 second
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
startActivity(intent);
finish();
}
}, interval);
You have to set Layout in onCreate method of Splash activity like:
setContentView(R.layout.splash);

Android app start up animation

i just need to know how is it possible to create a start-up animation in your app. When the app is launched I would like it to go through custom animation and then it reaches the content of the app (main activity) ...
Thanks for all your help
If you really want a "startup" screen, just load up another activity before the MainActivity and display that screen for x amount of time:
public class SplashScreen extends Activity {
// Splash screen timer
private static int TIME_OUT = 5000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_layout);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
finish();
}
}, TIME_OUT);
}
}

Force splash to show from onCreate Activity

My app has the following Activities:
DashboardActivity
SplashActivity
MainActivity
This how the flow is required:
The dash board has a button that starts up the MainActivity. The onCreate() method of the main activity checks if a user-profile was previously created, if yes, then it starts normally (this is fast, no GUI delay).
If no user-profile is found, then it's required to display a splash screen having instructions/how-to for the mainActivity, meanwhile the onCreate() of the main activity creates a new user-profile file(slow and GUI blocking).
What I'm currently see is the splash/instructions showing delayed after the slow user-profile creation ends.
Here is a code snippet from MainActivity.
private void showUsage(){
Thread splashTread = new Thread() {
public void run() {
try {
Intent instructionIntent = new Intent(MainActivity.this,
InstructionsActivity.class);
startActivity(instructionIntent);
} catch (Exception e) {
e.printStackTrace();
}
}
};
splashTread.start();
}
#Override //MainActivity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
if (!IsProfileExists()){
showUsage();
try{
createUserProfile(); //slow!
} catch (Exception e) { }
}
/*Continue with MainActivity*/
}
The Splash dismisses itself by a click:
public class InstructionsActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.instructions_layout);
ImageView instructions = (ImageView) findViewById(R.id.ivInstructions);
instructions.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
}
The problem:
The Instructions Activity (splash) shows after the GUI gets block from the MainActivity onCreate().
Any clues?
Do the condition check (IsProfileExists()) from dashBoardActivity and call the Splash activity if profile doesn't exist.

Android Activity Splash Screen

I have a splash screen which displays for 2-3 sec before it disappears.
I want to add a Fade in Effect when the next activity is loaded. I saw an Example in the Facebook Hacker Example and i am using it.
It uses a finish(); to end that activity to so from the DashboardActivity if some one clicks back it doesnt return back to the SplashAcitivty. But using this doesnt create the Fade in Effect as show in the API demos Examples.
public class SplashActivity extends Activity {
private long splashDelay = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// Remove notification bar
/*
* this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
* WindowManager.LayoutParams.FLAG_FULLSCREEN);
*/
setContentView(R.layout.activity_splash);
TimerTask task = new TimerTask() {
#Override
public void run() {
finish();
startActivity(new Intent().setClass(SplashActivity.this,
MainActivity.class));
overridePendingTransition(R.anim.fade, R.anim.hold);
}
};
Timer timer = new Timer();
timer.schedule(task, splashDelay);
}
}
Use a handler for this:
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
startActivity(new Intent(SplashActivity.this,
MainActivity.class));
overridePendingTransition(R.anim.fade, R.anim.hold);
finish();
}
}, splashDelay);

How to create a splash activity , call a second activity via a button, simple data form 5 fields and 2 buttons

New to Android need help with one solid build that I can refer to and study for future projects.
The first activity is a background image with a button,when clicked the it takes
you to the second activity which is a form with 5 data fields and 2 buttons.
One button calls an intent to take a picture within the app and one button that submits the data from the form along with the picture to URL.
lastly a third activity that says complete thank you. I can make some of this but don't know how to link button or open and merge camera with the app to be sent as a package of data. I suppose I could also hook into GPS acquire location as well as the camera call?
I'll tackle the splash screen activity, since it was slightly annoying to me that Android doesn't have support for it. It's actually pretty simple. Just add an activity called SplashScreenActivity composed of just a background image, but in the AndroidManifest.xml include the following options:
<activity android:name=".SplashScreenActivity" android:noHistory="true" android:configChanges="orientation|keyboardHidden|keyboard">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Inside the activity just move to the next activity after a sleep:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splash);
handler = new Handler();
}
#Override
protected void onResume() {
super.onResume();
thread = new Thread() {
#Override
public void run() {
try {
Thread.sleep(SPLASH_SCREEN_TIME_IN_MILLIS);
handler.post(new Runnable() {
public void run() {
goToNextScreen();
}
});
} catch (InterruptedException e) {
}
}
};
thread.start();
}
protected void goToNextScreen() {
Intent intent = new Intent(this, RealStartingActivity.class);
startActivity(intent);
}
Hope this helps.
Solution by Micah Hainline did not work for me - Splash screen has never appeared, instead black screen was shown and then main activity was started. Here is the solution I found at http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/ that works as I expected
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
#Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
Should take care of screen rotation while splash screen is shown, otherwise two activities could be created.
public class SplashActivity extends AppCompatActivity {
private static final String TAG = "SplashActivity";
private static final long SPLASH_TIME_OUT = DateUtils.SECOND_IN_MILLIS * 2;
private Handler mHandler;
private Runnable mGoNextRunnable;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
mHandler = new Handler();
mGoNextRunnable = new Runnable() {
#Override
public void run() {
startActivity(new Intent(SplashActivity.this, LoginActivity.class));
finish();
}
};
mHandler.postDelayed(mGoNextRunnable, SPLASH_TIME_OUT);
}
#Override
protected void onDestroy() {
super.onDestroy();
mHandler.removeCallbacks(mGoNextRunnable);
}
}

Categories

Resources