0

onClickメソッドで新しいページに新しいアクティビティを作成するだけでなく、ループの終了をトリガーして、誰かがスプラッシュ画面の背景をクリックしても、ループが停止した後に新しい画面がリロードされないようにしたいです。 。

これが私のコードです、

package clouds.clouds;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class splash extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
     Thread logotimer = new Thread() {


            @Override
            public void run(){
                try{
                    int logotimer = 0;
                    while(logotimer <5000) {
                        sleep(100);
                        logotimer = logotimer +100;

                    }
                    startActivity(new Intent("clouds.clouds.SPLASH"));
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                finally{
                    finish();
                }

            }



        };
      logotimer.start();


}



    public void onClickz(View v){}
    public void speed2 (View v){

        startActivity(new Intent("clouds.clouds.BUTTONZ"));
    }



}

助言がありますか?

4

4 に答える 4

3

クラスにブール変数を追加volatileします (それを と呼びますcancelled)。trueボタンがクリックされたときに設定し、状態を確認cancelled == falseしますwhile

public class splash extends Activity {

    volatile bool cancelled = false;
...

protected void onCancel(...)
{
    cancelled = true;

...

while(!cancelled && logotimer <5000) {
...
于 2012-07-15T01:16:16.133 に答える
3

メソッドを呼び出しlogotimer.interrupt()ますonClick()。これInterruptedExceptionにより、何もしないで処理する必要があるスレッド内で発生するはずです(または、スレッドを中断するときにやりたいことは何でも)

于 2012-07-15T01:46:01.863 に答える
0
package clouds.clouds;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class splash extends Activity {
Thread logotimer;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

     logotimer = new Thread();
     Thread logotimer = new Thread() {

            @Override
            public void run(){
                try{
                    int logotimer = 0;
                    while(logotimer <5000) {
                        sleep(100);
                        logotimer = logotimer +100;
                    }
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                finally{
                    finish();
                }
                startActivity(new Intent("clouds.clouds.SPLASH"));
            }



        };
      logotimer.start();


}


public void onClickz (View v){}
public void speed2 (View v){
    logotimer.interrupt();
    startActivity(new Intent("clouds.clouds.BUTTONZ"));
}






}
于 2012-07-15T22:40:20.673 に答える
0
boolean exit = false;
int logotimer = 0;
while(logotimer <5000 && exit != false) {
  sleep(100);
  logotimer = logotimer +100;
  // value = ???    
  if(logotimer == value) {
      exit = true;
  }
}
于 2012-07-15T02:23:17.647 に答える