Reputation: 51
How do I increase timer of the splash screen ? I need it to be slower.
public class MainActivity extends Activity {
private Handler mHandler = new Handler();
ImageView imageview;
int alpha = 255;
int b = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageview = (ImageView) this.findViewById(R.id.imageView1);
imageview.setAlpha(alpha);
new Thread(new Runnable() {
public void run() {
initApp();
while (b < 2) {
try {
if (b == 0) {
Thread.sleep(1000);
b = 1;
} else {
Thread.sleep(50);
}
updateApp();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
imageview.setAlpha(alpha);
imageview.invalidate();
}
};
}
public void updateApp() {
alpha -= 5;
if (alpha <= 0)
{
b = 2;
Intent in = new Intent(this, TabsLayoutActivity.class);
startActivity(in);
this.finish();
}
mHandler.sendMessage(mHandler.obtainMessage());
}
public void initApp(){
}
}
Upvotes: 0
Views: 469
Reputation: 2188
You can also use Handler for splash screen like below..
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// TODO Auto-generated method stub
finish();
Intent menu = new Intent(getBaseContext(), MainMenu.class);
startActivity(menu);
}
}, 3000);
Here 3000 = 3 seconds.You can replace the time as you needed.Hope it will help you.
Upvotes: 1
Reputation: 22493
Increase sleep time
Thread.sleep(3000); /// 3000 milli seconds i.e 3 sec
if you want more just increase that number.
Upvotes: 0