我爲Android設計了一個應用程序,其中我在主要活動啓動之前顯示啓動畫面,但應用程序需要5-7秒才能啓動低端設備。我想把時間縮短到儘可能低的程度。我一直試圖減少onCreate()
中的事情,但現在我無法從中刪除任何更多的東西。我正在粘貼我用來顯示啓動畫面和MainActivity代碼的代碼。請幫助我減少應用程序的啓動時間。如何讓android應用加載速度更快?
Splash.java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash);
txtLoad = (TextView) findViewById(R.id.txtLoading);
txtLoad.setText("v1.0");
new Thread() {
public void run() {
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
finish();
Intent intent = new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
}
}
}.start();
}
MainActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
editType1UserName = (EditText) findViewById(R.id.editTextType1UserName);
editType1Password = (EditText) findViewById(R.id.editTextType1Password);
editType2UserName = (EditText) findViewById(R.id.editTextType2UserName);
editType2Password = (EditText) findViewById(R.id.editTextType2Password);
editType3UserName = (EditText) findViewById(R.id.editTextType3UserName);
editType3Password = (EditText) findViewById(R.id.editTextType3Password);
editType4UserName = (EditText) findViewById(R.id.editTextType4UserName);
editType4Password = (EditText) findViewById(R.id.editTextType4Password);
mTxtPhoneNo = (AutoCompleteTextView) findViewById(R.id.mmWhoNo);
mTxtPhoneNo.setThreshold(1);
editText = (EditText) findViewById(R.id.editTextMessage);
spinner1 = (Spinner) findViewById(R.id.spinnerGateway);
btnsend = (Button) findViewById(R.id.btnSend);
btnContact = (Button) findViewById(R.id.btnContact);
btnsend.setOnClickListener((OnClickListener) this);
btnContact.setOnClickListener((OnClickListener) this);
mPeopleList = new ArrayList<Map<String, String>>();
PopulatePeopleList();
mAdapter = new SimpleAdapter(this, mPeopleList, R.layout.custcontview,
new String[] { "Name", "Phone", "Type" }, new int[] {
R.id.ccontName, R.id.ccontNo, R.id.ccontType });
mTxtPhoneNo.setAdapter(mAdapter);
mTxtPhoneNo.setOnItemClickListener((OnItemClickListener) this);
readPerson();
Panel panel;
topPanel = panel = (Panel) findViewById(R.id.mytopPanel);
panel.setOnPanelListener((OnPanelListener) this);
panel.setInterpolator(new BounceInterpolator(Type.OUT));
getLoginDetails();
}
你在'PopulatePeopleList()'方法中做了什麼?如果您正在查詢手機上的聯繫人提供程序(並且按照您的代碼的外觀,這是您的操作),我希望您在「CursorLoader」中執行此操作,否則您可能會遇到與您看到的性能有關的問題。 – Luksprog
@Luksprog是的,我在'PopulatePeopleList'中使用聯繫人提供程序..你可以向我解釋什麼是遊標加載程序,以及我如何將應用程序啓動時間devrease。 –
這可能是一個不錯的主意,只是把一個啓動畫面。然後,應用程序的用戶並不認爲這是一個緩慢的加載,因爲他們專注於你的啓動畫面,一旦完成,應用程序就在那裏所有裝載完美。 – edwoollard