user3160965
user3160965

Reputation: 106

I need to do a splashscreen

In iOS I would do this:

    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 768, 1024)];
splashView.image = [UIImage imageNamed:@"Default.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
splashView.alpha = 0.0;
splashView.frame = CGRectMake(-60, -60, 900, 1200);
[UIView commitAnimations];

And then "push" a view controller to go on.

I have looked at various examples and tutorials and cannot get a handle on what code is needed to:

  1. Display a splashscreen
  2. Have it fade out
  3. Have another view (action?) displayed.

Some posted this which I adapted but the commented code yields an error. I must be missing something.

Upvotes: 0

Views: 346

Answers (1)

user874649
user874649

Reputation:

public class SplashScreen extends Activity {
protected boolean _active = true;
protected int _splashTime = 3000;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.splash);

    // thread for displaying the SplashScreen
    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(
                        "com.android.NextActivity"));
            }
        }
    };
    splashTread.start();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        _active = false;
    }
    return true;
}

}

and splash.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="fill_parent"
android:layout_height="fill_parent"  >
<ImageView android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:src="@drawable/your_image_here" />
</LinearLayout>

Upvotes: 1

Related Questions