我的启动画面出现错误,它会强制关闭应用程序。在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;
}
}
答案 0 :(得分: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();
}
答案 1 :(得分:1)
您的问题是您没有将 QuizActivity 添加到AndroidMainfest.xml
<activity android:name="QuizActivity" ></activity>
应该解决你的问题。 并且你可以在splash make中启动新的Activity
finish();
比你不能用后退键返回它=)
答案 2 :(得分: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();
}
});
}
}
};