I have an Android app that shows a frame-by-frame animation activity. At the end of the animation it starts a background service and closes the activity. Here is the code:
cont = getApplicationContext();
final ImageView img = (ImageView)findViewById(R.id.img);
img.setBackgroundResource(R.drawable.intro);
img.post(new Runnable() {
public void run() {
animation = (AnimationDrawable)img.getBackground();
animation.setOneShot(true);
animation.start();
timer = new Timer();
timer.schedule(new timer_exp(), 3400);
}
});
}
class timer_exp extends TimerTask{
@Override
public void run() {
//start service
Intent serviceIntent = new Intent(cont, MainService.class);
startService(serviceIntent);
//kill activity
finish();
}
}
When I run the app I can see the animation and then the service starts. When I press on the app’s icon again, I get a black screen and the app crashes.
Any Ideas to what the problem might be?
Thanks,
PB
After some investigation, it turned out that the service was the problem.
I had some
Thread.sleep()in several places that caused the UI thread to crash.After adding another thread for these actions the problem solved.