4

みなさん、こんにちは!

別のアクティビティが終了するまでメソッドの実行を停止する必要があります。現時点では、私はこの方法でそれをやろうとしています:

    private boolean isPausedWhileSplash;

public void showSplashWorldChangeAd(String oldWorldName, String newWorldName) {
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    Intent intent = new Intent(this, SplashScreen.class);
    intent.putExtra(SplashScreen.MSG_STRING_KEY, oldWorldName + " -> "
            + newWorldName);
    intent.putExtra(SplashScreen.OLD_WORLD, oldWorldName);
    intent.putExtra(SplashScreen.NEW_WORLD, newWorldName);
    startActivityForResult(intent, RESULT_OK);
    isPausedWhileSplash = true;
    while (isPausedWhileSplash) {
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    isPausedWhileSplash = false;
}

しかし、それは機能していません。

手伝って頂けますか?

ありがとう!

UPD:ビューが描画されないようにする方法はありますか? 私が今必要としているのは、このアクティビティのビューを再描画するメソッドの呼び出しを遅らせることだけだからです。これで、ワールドの変更について説明するスプラッシュ スクリーンが表示される前に新しいワールドが描画されましたが、見栄えがよくありません。

4

2 に答える 2

3

私は少し時間が急いでいるので、ここに一般的な答えがあります:

public class MonitorObject{
}

public class MyWaitNotify{

  MonitorObject myMonitorObject = new MonitorObject(); //To be used for synch

  public void doWait(){
    synchronized(myMonitorObject){
      try{
        myMonitorObject.wait(); // Wait until the notify method is called by another thread
      } catch(InterruptedException e){...}
    }
  }

  public void doNotify(){ //Notify waiting threads that they can continue
    synchronized(myMonitorObject){
      myMonitorObject.notify();
    }
  }
}

それまでに解決策が見つからない場合は、今日の午後に戻ってきて実際の例を紹介します...

この記事から始める必要があります

編集: この記事では、他のアプローチを示しています。これらはすべて、現在のソリューションを改善するものです。さまざまなスレッドのイベントから UI を更新する方法と、さまざまなソリューションのメリット/コストについて説明します。

于 2012-08-20T08:12:23.693 に答える
1

私はあなたがこのようなことをしようとしていると思います:

public void showSplashWorldChangeAd(String oldWorldName, String newWorldName){
    /* You have done some initialization work */
    startActivityForResult(intent, RESULT_OK);
    /* This is what you want to do after the activity returns */
    afterActivityReturns();
}

では、なぜこのように進めないのでしょうか。

public void showSplashWorldChangeAd(String oldWorldName, String newWorldName){
        /* You have done some initialization task here*/
        startActivityForResult(intent, RESULT_OK);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /* This is what you want to do after the activity finishes */
        afterActivityReturns();
    }

showSplashWorldChangeAdしかし、何らかの理由で本当にメソッドを停止したい場合は、ロックとキーが必要です (Basic が言うように)。

于 2012-08-20T08:24:33.310 に答える