我正在關閉另一個例子(在這裏找到Loading MP3s into the Sound Pool in Android)。但由於某種原因,我結束了兩個onCreate()
方法,如果我刪除一個我收到錯誤。Android中的兩個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);
}
}
因此,您在應用程序類中有1個'onCreate',在'Activity'中有另外1個,這沒關係。問題是爲什麼你要在1個文件中粘貼Application和Activity。 – ernazm
我認爲這是如何做到這裏:http://stackoverflow.com/questions/7061594/loading-mp3s-into-the-sound-pool-in-android如果我把它放在一個單獨的文件,我該怎麼稱呼它? – Ryan