0

我的启动画面出现错误,它将强制关闭应用程序。在 Logcat 中说 Permission Denied。我应该怎么做才能解决这个问题。谁能帮我解决这个问题,非常感谢

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

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

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        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.droidnova.android.splashscreen.BodyPartsGameActivity"));
                    stop();
                }
            }
        };
        splashTread.start();
    }

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

3 回答 3

1

这样做会更容易:

private ImageView img;
    private Thread t;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        img = (ImageView)findViewById(R.id.im1);

        t = new Thread(){   
            @Override
            public void run() {
                try {
                    synchronized(this){ 
                        wait(2000);
                    }
                      // Here your code of animation

                } 
                catch(InterruptedException ex){ 
                    ex.printStackTrace();
                }

                Intent i = new Intent(QuizActivity.this,main.class);
                startActivity(i);
            }
        };
            t.start();
    }
于 2012-05-14T06:59:55.540 回答
1

您的问题是您没有将QuizActivity添加到 AndroidMainfest.xml

 <activity android:name="QuizActivity" ></activity>

比你的问题应该得到解决。在你开始新的活动之前

finish();

比你不能用返回键返回它=)

于 2012-05-14T07:07:38.143 回答
0

你可以试试这个一次..

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 {
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            finish();
                            startActivity(new Intent("com.droidnova.android.splashscreen.BodyPartsGameActivity"));
                            stop();
                        }
                    });
                }
            }
        };
于 2012-05-14T07:10:45.720 回答