フレームごとのアニメーションアクティビティを表示するAndroidアプリがあります。アニメーションの最後に、バックグラウンドサービスを開始し、アクティビティを閉じます。コードは次のとおりです。
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();
}
}
アプリを実行すると、アニメーションが表示され、サービスが開始されます。アプリのアイコンをもう一度押すと、画面が真っ暗になり、アプリがクラッシュします。
問題が何であるかについてのアイデアはありますか?
ありがとう、PB