Issue
I want to display a splash screen for x seconds at the app launch from a PNG file on the device.
I have tried android:windowBackground in the theme however that cannot be taken from a file and only predefined Drawable
The file may change at anytime so at next app launch it will be different.
Solution
Below is the code to set timer for Splash Screen activity. Also, do not forget to include the activity in manifest.
splash_screen.java
public class Splash extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
Thread timerThread = new Thread(){
public void run(){
try{
sleep(5000); //Change the timing of the Screen
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent intent = new Intent(SplashScreen.this,MainActivity.class);
startActivity(intent);
}
}
};
timerThread.start();
}
}
Make your layout, full screen, remove action bar. Here's the code for splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splashscreen"
android:orientation="vertical">
</LinearLayout>
Change the image of splashscreen, when you need, in your case, each time app is launched. HTH.
Answered By - Anirudh Murali
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.