-
Notifications
You must be signed in to change notification settings - Fork 18
/
SplashActivity.java
60 lines (49 loc) · 1.48 KB
/
SplashActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Licensed Materials - Property of IBM
* © Copyright IBM Corporation 2015. All Rights Reserved.
*/
package com.ibm.mil.splashscreendemo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
public class SplashActivity extends Activity {
private static final long SPLASH_DURATION = 2500L;
private Handler mHandler;
private Runnable mRunnable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
mHandler = new Handler();
mRunnable = new Runnable() {
@Override
public void run() {
dismissSplash();
}
};
// allow user to click and dismiss the splash screen prematurely
View rootView = findViewById(android.R.id.content);
rootView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismissSplash();
}
});
}
@Override
protected void onResume() {
super.onResume();
mHandler.postDelayed(mRunnable, SPLASH_DURATION);
}
@Override
protected void onPause() {
super.onPause();
mHandler.removeCallbacks(mRunnable);
}
private void dismissSplash() {
startActivity(new Intent(this, MainActivity.class));
finish();
}
}