Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm making an android app which has a splash screen and I want to give an animation t it. I successfully added animation to it but what i want is after 5 seconds next intent should open. but now it directly opens the second intent and splash screen is not running. my launch activity is splash screen. below is the code for animation and splash screen.
Blink.xml
XML
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="10000"
        android:repeatMode="reverse"
        android:repeatCount="infinite"/>
</set>


Splashscreen.java
Java
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);
        blink(new View(getApplicationContext()));

    }

 public void blink(View view){
        ImageView image = (ImageView)findViewById(R.id.imageView);
        Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
        image.startAnimation(animation1);
        Intent mainIntent=new Intent(SplashScreen.this,MainActivity.class);
        mainIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(mainIntent);
        finish();
    }
Posted

1 solution

you need to add an Animation Listener[^] to your activity.
And the onAnimationEnd()[^] you can start your new intent.
Something like this,
Java
public void blink(View view){
        ImageView image = (ImageView)findViewById(R.id.imageView);
        Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
        animation1.setAnimationListener(new AnimationListener() {
            public void onAnimationStart(Animation animation) {}
            public void onAnimationRepeat(Animation animation) {}
            public void onAnimationEnd(Animation animation) {
                       // your intent to start
            }
        }    
image.startAnimation(animation1);
        finish();
    }


-KR
 
Share this answer
 
Comments
ridoy 25-Oct-15 14:52pm    
5ed!
Krunal Rohit 26-Oct-15 0:22am    
Thanks ridoy :)

-KR
bhavikadb 26-Oct-15 0:41am    
Thank you KrunalRohit for your answer. Now Since i have written

android:duration="10000"
android:repeatMode="reverse"
android:repeatCount="infinite"

in blink.xml it doesn't open next intent. So I changed repeatCount to Zero(0). Now it runs perfectly but when i write code in onStartAnimation which downloads code from server the next intent is open after the given duration in blink.xml. So what should i do to run the splash screen till all the data is downloaded?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900