Display Splash Screen for 1.5 Seconds and then redirect to Home Screen:
package com.hp;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
public class SplashScreenActivity extends Activity
{
protected boolean _active = true;
protected int _splashTime = 1500;
private ImageView homeScreen = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
homeScreen = new ImageView(this);
homeScreen.setLayoutParams(new LayoutParams(width, height));
homeScreen.setImageResource(R.drawable.atmosplash);
homeScreen.setScaleType(ScaleType.FIT_XY);
setContentView(homeScreen);
final Thread splashTread = new Thread()
{
@Override
public void run()
{
try
{
int waited = 0;
while(_active && (waited < _splashTime))
{
sleep(100);
if(_active)
{
waited += 100;
}
}
}
catch(InterruptedException e)
{
// do nothing
}
finally
{
finish();
startActivity(new Intent(SplashScreenActivity.this,
HomeScreenActivity.class));
stop();
}
}
};
splashTread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
_active = false;
}
return true;
}
}
package com.hp;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
public class SplashScreenActivity extends Activity
{
protected boolean _active = true;
protected int _splashTime = 1500;
private ImageView homeScreen = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
homeScreen = new ImageView(this);
homeScreen.setLayoutParams(new LayoutParams(width, height));
homeScreen.setImageResource(R.drawable.atmosplash);
homeScreen.setScaleType(ScaleType.FIT_XY);
setContentView(homeScreen);
final Thread splashTread = new Thread()
{
@Override
public void run()
{
try
{
int waited = 0;
while(_active && (waited < _splashTime))
{
sleep(100);
if(_active)
{
waited += 100;
}
}
}
catch(InterruptedException e)
{
// do nothing
}
finally
{
finish();
startActivity(new Intent(SplashScreenActivity.this,
HomeScreenActivity.class));
stop();
}
}
};
splashTread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
_active = false;
}
return true;
}
}
Thanks
akm
www.cdacians.com
No comments:
Post a Comment