您好我显示屏幕3秒然后我开始新活动但是在Android 5.0上有一个黑屏近10秒和ANR。这是活动的所有代码,显示3秒钟:
private static final ScheduledExecutorService worker =
Executors.newSingleThreadScheduledExecutor();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Crashlytics.start(this);
setContentView(R.layout.splash_fragment);
Runnable task = new Runnable() {
public void run() {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
};
worker.schedule(task, 3, TimeUnit.SECONDS);
}
来自logcat的日志:
Activity destroy timeout for ActivityRecord
I/InputDispatcher( 725): Application is not responding: AppWindowToken
It has been 5005.0ms since event, 5003.6ms since wait started.
Reason: Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.
I/WindowManager( 725): Input event dispatching timed out sending to application AppWindowToken
Reason: Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.
我做错了什么,如何解决?
答案 0 :(得分:4)
为什么在你有一个简单的过程中进行漫长的过程。正如@Chen在上面评论的那样,你可以像这样开始MainAcitivity
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
}, 3000);