Many Applications, mostly games, on the market show splash screens. With this screen they prompt a logo for the application and/or the author.
I will show you a short way to implement a splash screen which will occur on every startup, will stay for a number of seconds you can define, will close on touching the screen and will not reappear on pressing the back button.
I created an empty project named SplashScreen with the activity SplashScreen. This activity will display the splash screen, so we have to create a new activity which will be the first real view you want to display.
Slacescreen.java :
public class splashscreen extends Activity
{
public boolean active =true;
public int stime =5000;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread sp =new Thread()
{
public void run()
{
try
{
int waited =0;
while (active && (waited < stime))
{
sleep(100);
if(active)
{
waited +=100;
}
}
}
catch (InterruptedException e)
{
Log.d("Exception","Exception"+e.toString());
}
finally
{
finish();
Intent i=new Intent(getApplicationContext(),SplashActivity.class);
startActivity(i);
}
}
};
sp.start();
}
}
In above code there is a SplaceActivity.class ,is transfer the next screen after the slace screen.
I will show you a short way to implement a splash screen which will occur on every startup, will stay for a number of seconds you can define, will close on touching the screen and will not reappear on pressing the back button.
I created an empty project named SplashScreen with the activity SplashScreen. This activity will display the splash screen, so we have to create a new activity which will be the first real view you want to display.
Slacescreen.java :
public class splashscreen extends Activity
{
public boolean active =true;
public int stime =5000;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread sp =new Thread()
{
public void run()
{
try
{
int waited =0;
while (active && (waited < stime))
{
sleep(100);
if(active)
{
waited +=100;
}
}
}
catch (InterruptedException e)
{
Log.d("Exception","Exception"+e.toString());
}
finally
{
finish();
Intent i=new Intent(getApplicationContext(),SplashActivity.class);
startActivity(i);
}
}
};
sp.start();
}
}
In above code there is a SplaceActivity.class ,is transfer the next screen after the slace screen.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.