Android实现欢迎界面,点击进入应用

在主线程中开启一个新线程,每隔100ms检查一下时间是否到达自己预设的显示时间,到达则进入应用

实现屏幕的触摸事件,当触摸的时候,进入应用

package com.example.administrator.bigelephantbike;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.Window;

public class WelcomePageActivity extends Activity {
    protected boolean _active = true;
    protected int _splashTime = 5000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_welcome_page);
        Thread splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while (_active && (waited < _splashTime)) {
                        sleep(100);
                        if (_active) {
                            waited += 100;
                            Log.d("hh", "wait");
                        }
                    }
                } catch (InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
                    Intent intent =new Intent(WelcomePageActivity.this,MipcaActivityCapture.class);
                    intent.putExtra("name","welcome");
                    startActivity(intent);
                    Log.d("hh", "start 扫描");
                    finish();
                }
            }
        };
        splashTread.start();
    }

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

 

posted @ 2016-04-28 17:19  艳鬼  阅读(613)  评论(0编辑  收藏  举报