我作爲ativity加載到初始化文字轉語音API的對象,但它需要4-5秒的時候我初始化啓動活動我TTS object.I試圖在異步任務和線程對其進行初始化但結果是一樣的。我怎樣才能讓我的活動更快加載?這是我的線程的代碼,它初始化TTS對象。Android的活動的時間太長加載
class LoadingThread implements Runnable{
@Override
public void run() {
//load settings of the app
appSettings = new AppSettings(getApplicationContext());
appSettings.loadSettings();
//making ready TTS before the user interact with it
textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
ttsOptions = new HashMap<String, String>();
ttsOptions.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,ActivityMain.UTTER_ID);
textToSpeech.setLanguage(Locale.ENGLISH);
textToSpeech.setSpeechRate(AppSettings.getSpeakerSpeed());
}
});
textToSpeech.setOnUtteranceCompletedListener(new TextToSpeech.OnUtteranceCompletedListener() {
@Override
public void onUtteranceCompleted(String s) {
ActivityMain.mNotepad.onStopSpeaker(s);
}
});
}
}
我打電話給我的活動)中的onResume這個線程(如
LoadingThread thread = new LoadingThread();
thread.run();
你可以發佈你的整個的onCreate請與XML的活動。 – apmartin1991
您是否在真實設備上嘗試過您的應用?因爲模擬器可能有足夠多的時間啓動。 – katmanco
@katmanco我用我的真實設備而不是虛擬設備 –