私は別の例(ここで見つけたLoading MP3s into the Sound Pool in Android)を取り組んでいます。何らかの理由で私は2つのonCreate()
メソッドで終わってしまいます。もし私が1つ削除すればエラーが出ます。Androidの2つのonCreate()メソッド?
私はMP3をSoundpoolに一度ロードしてから、他のアクティビティでそれらを呼び出そうとしています。
マイコード:
class MyApp extends Application {
private static MyApp singleton;
private static SoundPool mSoundPool;
public onCreate() { // ##### Deleting this gives me errors ###, not deleting it gives me 1 error.
super.onCreate();
singleton = this;
mSoundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);// Just an example
}
public static MyApp getInstance() {
return singleton;
}
public SoundPool getSoundPool() {
return mSoundPool;
}
}
public class TestAndroidGlobalsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
アプリケーションクラスに 'onCreate'が1つあり、' Activity'にもう1つあります。これは大丈夫です。問題は、1つのファイルに 'Application'と' Activity'を張っている理由です。 – ernazm
私はそれがここでどうやっているのかと思った:http://stackoverflow.com/questions/7061594/loading-mp3s-into-the-sound-pool-in-android私はそれを別ファイルに入れたらどうやって呼び出すの? – Ryan