我为 android 设计了一个应用程序,其中我在主要活动启动之前显示了一个启动屏幕,但该应用程序需要 5-7 秒才能在低端设备上启动。我想将时间减少到尽可能低。我一直在努力减少要做的事情,onCreate()
但现在我不能再从中删除任何东西了。我正在粘贴用于显示启动画面的代码和 MainActivity 中的代码。请帮助我减少应用程序的启动时间。
飞溅.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();
}