-
-
Save pyadav/9cc238e05248abd5b515174beb832ce3 to your computer and use it in GitHub Desktop.
Simple Splash screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SplashScreen extends Activity { | |
private Handler mHandler; | |
private Runnable myRunnable; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
// Just create simple XML layout with i.e a single ImageView or a custom layout | |
setContentView(R.layout.splash_screen_layout); | |
mHandler = new Handler(); | |
myRunnable = new Runnable() { | |
@Override | |
public void run() { | |
Intent intent = new Intent(SplashScreen.this, MainActivity.class); | |
startActivity(intent); | |
finish(); | |
} | |
}; | |
} | |
@Override | |
public void onBackPressed() { | |
// Remove callback on back press | |
if (mHandler != null && myRunnable != null) { | |
mHandler.removeCallbacks(myRunnable); | |
} | |
super.onBackPressed(); | |
} | |
@Override | |
protected void onPause() { | |
// Remove callback on pause | |
if (mHandler != null && myRunnable != null) { | |
mHandler.removeCallbacks(myRunnable); | |
} | |
super.onPause(); | |
} | |
@Override | |
protected void onResume() { | |
// Attach and start callback with delay on resume | |
if (mHandler != null && myRunnable != null) { | |
mHandler.postDelayed(myRunnable, ConstantValues.SPLASH_TIME_OUT); | |
} | |
super.onResume(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment