how to make the android app load faster?
Posted
by
Tapan Desai
on Stack Overflow
See other posts from Stack Overflow
or by Tapan Desai
Published on 2012-10-07T07:40:54Z
Indexed on
2012/10/07
9:37 UTC
Read the original article
Hit count: 350
I have designed an application for android, in which i am showing a splash screen before the main activity is started but the application takes 5-7 seconds to start on low-end devices. I want to reduce that time to as low as possible. I have been trying to reduce the things to be done in onCreate()
but now i cannot remove any thing more from that. I am pasting the code that i have used to show the splash and the code from MainActivity. Please help me in reducing the startup time of the application.
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();
}
© Stack Overflow or respective owner