SDK : 0.9-r1
The basic logic is to use a thread to do all the background work while the image is being displayed. There are no changes in this code as far as the new SDK is concerned.
public class Splashscreen extends Activity
{
ImageView splash;
final Handler mHandler = new Handler();
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
splash = (ImageView) findViewById(R.id.splash);
Thread t = new Thread()
{
public void run()
{
mHandler.postDelayed(update, 4000);
}
};
t.start();
}
- mHandler is used to send the runnable when our data processing is done.
final Runnable update = new Runnable()
{
public void run()
{
splash.setVisibility(View.GONE);
}
};
}
The update Runnable object will run when it receives the runnable from mHandler.
The above code takes-off the image after 4 seconds. But in most conditions, you would want to remove it as soon as the processing is done. For this, replace the postDelayed message with mHandler.post(update); In this case, if your application requires less processing during startup, the splashscreen will not be visible.
No comments:
Post a Comment