I have a 2 part splash screen that I’ve been trying to get to work on Android 2.2 (eclipse emulator) Everything works in 2.3 emulator. In 2.2 it works more often than not – sometimes goes to black screen – sometimes I need to restart the emulator. If I try to click the screen to cancel the splash and go right to the main activity, it goes to black screen and in the log I see:
06-29 12:23:54.474: I/ActivityManager(58): Starting activity: Intent { cmp=org.test.game/.MainActivity }
06-29 12:23:54.494: W/System.err(278): java.lang.InterruptedException
06-29 12:23:54.504: D/qemud(37): fdhandler_accept_event: accepting on fd 10
06-29 12:23:54.504: D/qemud(37): created client 0x17fe8 listening on fd 15
06-29 12:23:54.504: D/qemud(37): client_fd_receive: attempting registration for service 'sensors'
06-29 12:23:54.504: D/qemud(37): client_fd_receive: -> received channel id 11
06-29 12:23:54.514: D/qemud(37): client_registration: registration succeeded for client 11
06-29 12:23:54.524: D/qemud(37): fdhandler_accept_event: accepting on fd 10
06-29 12:23:54.524: D/qemud(37): created client 0x18038 listening on fd 16
06-29 12:23:54.524: D/qemud(37): fdhandler_event: disconnect on fd 15
06-29 12:23:54.544: W/System.err(278): at java.lang.VMThread.sleep(Native Method)
06-29 12:23:54.554: W/System.err(278): at java.lang.Thread.sleep(Thread.java:1306)
06-29 12:23:54.554: W/System.err(278): at java.lang.Thread.sleep(Thread.java:1286)
06-29 12:23:54.564: W/System.err(278): at org.test.game.Splash$SplashScreenDelay.doInBackground(Splash.java:121)
06-29 12:23:54.574: W/System.err(278): at org.test.game.Splash$SplashScreenDelay.doInBackground(Splash.java:1)
06-29 12:23:54.584: W/System.err(278): at android.os.AsyncTask$2.call(AsyncTask.java:185)
06-29 12:23:54.594: W/System.err(278): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-29 12:23:54.604: W/System.err(278): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-29 12:23:54.604: W/System.err(278): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
06-29 12:23:54.614: W/System.err(278): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
06-29 12:23:54.624: W/System.err(278): at java.lang.Thread.run(Thread.java:1096)
06-29 12:24:04.475: W/ActivityManager(58): Launch timeout has expired, giving up wake lock!
06-29 12:24:04.484: W/ActivityManager(58): Activity idle timeout for HistoryRecord{44eca1f8 org.test.game/.MainActivity}
06-29 12:24:14.494: W/ActivityManager(58): Activity destroy timeout for HistoryRecord{44ebb9b0 org.test.game/.Splash}
Inspired by http://webgarbage.de/splash-screen-on-android.html
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.ImageView;
public class Splash extends Activity {
private AsyncTask splashDelay;
private ImageView ivSplash;
private int splashCount = 0;
private int splashTime = 2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
ivSplash = (ImageView) findViewById(R.id.IVSplash);
splashDelay = new SplashScreenDelay().execute(splashTime);
}
//Touch screen to skip splash
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
splashDelay.cancel(true);
}
return true;
}
private class SplashScreenDelay extends AsyncTask<Integer, Integer, Integer> {
@Override
protected Integer doInBackground(Integer... params) {
try {
int count = 0;
while (count < params[0]*10) {
if(count % 10 == 0) {
Log.v("Splash", "Sleeping... " + count/10);
}
Thread.sleep(100);
count++;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
return new Integer(0);
}
@Override
protected void onPostExecute(Integer result) {
if (splashCount == 0) {
splashCount = 1;
ivSplash.setBackgroundResource(R.drawable.splash2);
splashDelay = new SplashScreenDelay().execute(splashTime);
}
else
startActivity(new Intent(getApplicationContext(), MainActivity.class));
}
protected void onCancelled() {
startActivity(new Intent(getApplicationContext(), MainActivity.class));
}
}
}
Any advice? What’s making the cancelling of the splash give a black screen?
I’ve read that “launch timeout has expired” error comes when the MainActivity has to wait too long, but if the splash works interrupted (more time) why should it fail when there is a cancel (less time)?
Thanks
An async task is not well suited for setting a timer on your splash screen. A more suitable method would be to use a Handler and sendDelayed to delay the splash screen.