Created
March 2, 2017 13:31
-
-
Save wajahatkarim3/2257249b14b4da8d956e19cf43d2a0e8 to your computer and use it in GitHub Desktop.
Splash Activity Snippet
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 SplashActivity extends Activity { | |
private static long SLEEP_TIME = 3; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(layout.activity_splash); | |
// Start timer and launch main activity | |
IntentLauncher launcher = new IntentLauncher(); | |
launcher.start(); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.splash, menu); | |
return true; | |
} | |
private class IntentLauncher extends Thread { | |
@Override | |
/** | |
* Sleep for some time and than start new activity. | |
*/ | |
public void run() { | |
try { | |
// Sleeping | |
Thread.sleep(SLEEP_TIME*1000); | |
} catch (Exception e) { | |
//Log.e(TAG, e.getMessage()); | |
} | |
// Start main activity | |
Intent intent = new Intent(SplashActivity.this, LoginActivity.class); | |
SplashActivity.this.startActivity(intent); | |
SplashActivity.this.finish(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment