0

Android アプリケーション クラスで SoungMagager クラスを作成したので、それを使用してアプリ全体でサウンドを管理できます。SoundManager には、短いサウンドと長いサウンドをそれぞれ再生するための SoundPool と MediaPlayer があります。

私を「クリーンアップ」するために、 onDestroy() メソッドに release() SoundPool と MediaPlayer のメソッドを配置し、finish() を呼び出してアプリを終了します。

私の問題は、この finish() を実行してすぐにアプリに戻ると、音が出なくなることです。サウンドプールやメディアプレーヤーはありません。

「ホーム」ハードウェアボタンを押して出て、もう一度アプリに戻ると、音がします。

私が終了した場合()、システムアプリ管理に移動し、アプリを強制的に閉じてから、アプリを再度実行すると、音がします。

Finish() の代わりに System.exit(0) を使用すると、すべて問題ありませんが、そうしないように言われます。

これは Application クラスのせいだと思いますが、よくわかりません。この問題を解決するにはどうすればよいですか? 助言がありますか?

4

1 に答える 1

0

I think you are putting soundpooland mediaplayerobject in the activity which you are going to finish() so obvioulsy when the activity is being destroyed its instance variable gets released(i mean deleted) so you need to assign the sound to the soundpool of your soundManager class so it will not be destroyed . I think you got my point.

public class SoundManager {

    public static SoundPool mSoundPool;
    public static MediaPlayer mMediaPlayer;
      .....
      ....
}

now in ur activity in which You are using the soundpool object do this :--

   class <your activity> extend Activity{
       @Override
   public void onCreate(Bundle savedInstanceState) {
             SoundManager.mSoundPool = <assign your audio>;
             SoundManager.mMediaPlayer = <assign>;
       }
} 
于 2012-11-01T05:33:18.450 に答える