Handlerを利用してボタンを何も押さなかったら前の画面に画面遷移するようにしています。
Image Buttonを押すと次の画面に画面遷移するようにしています。
しかし、画面遷移はできるのですが、onCreateでHandlerが実行されていて、Image Buttonで画面移動してもHandlerは停止せず、Handlerは実行されてしまいます。 Image Buttonを押したタイミングでHandlerを停止させる方法はありますか?
public class Question_Dirty extends Activity {
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.question_dirty_layout); //button1 イメージボタンの取得 ImageButton btn1=(ImageButton)findViewById(R.id.button1); //クリックイベントの通知先指定 btn1.setOnClickListener(new button1CliclListener()); //Handler の指定 Handler handler = new Handler(); // 切り替わる秒数(ミリ秒)を指定、今回は10秒 handler.postDelayed(new splashHandler(), 10000); } //button1を押したときの処理 private class button1CliclListener implements View.OnClickListener { @Override public void onClick(View v){ Intent intent =new Intent(Question_Dirty.this, Thanks_Question.class); startActivity(intent); } } // splashHandlerクラス class splashHandler implements Runnable { public void run() { Intent intent =new Intent(Question_Dirty.this, MainActivity.class); startActivity(intent); } }
}

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/04/06 01:16