启动android的时间太长,缓存太高
我正在开发一款Android应用程序,我刚刚意识到第一次启动该应用程序需要花费太多时间,这似乎是因为它在缓存中存储了大量信息(近16MB) 问题是,我不使用图像,它也不是一个如此复杂的应用程序。有什么问题吗 -第一次启动应用程序时,需要20秒才能打开。(并将缓存设置为16 Mb) -之后需要4秒才能打开(仍然很多) -如果我清除缓存并再次打开应用程序,则需要20秒才能打开(然后缓存又是16 Mb) 主要的活动就是一个有两个按钮的布局,就是这样 编辑:这是主要活动的代码启动android的时间太长,缓存太高,android,caching,startup,Android,Caching,Startup,我正在开发一款Android应用程序,我刚刚意识到第一次启动该应用程序需要花费太多时间,这似乎是因为它在缓存中存储了大量信息(近16MB) 问题是,我不使用图像,它也不是一个如此复杂的应用程序。有什么问题吗 -第一次启动应用程序时,需要20秒才能打开。(并将缓存设置为16 Mb) -之后需要4秒才能打开(仍然很多) -如果我清除缓存并再次打开应用程序,则需要20秒才能打开(然后缓存又是16 Mb) 主要的活动就是一个有两个按钮的布局,就是这样 编辑:这是主要活动的代码 package p
package pablopicazo.consejoswifi.activities;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import pablopicazo.consejoswifi.R;
import pablopicazo.consejoswifi.activities.test.TestDescription;
import pablopicazo.consejoswifi.activities.test.TestResults;
import pablopicazo.consejoswifi.activities.tools.Tools;
public class Main extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Declare layout elements
ImageView testwifiButon = (ImageView) findViewById(R.id.button_testwifi);
ImageView toolsButton = (ImageView) findViewById(R.id.button_tools);
//Buttons listeners
testwifiButon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//If there's a test made previously, show the results. Otherwise, starts new test
SharedPreferences sharedPref = getSharedPreferences("testAnswers", Context.MODE_PRIVATE);
if (sharedPref.getString("testResults", "").equals("")) {
Intent intent = new Intent(Main.this, TestDescription.class);
startActivity(intent);
} else {
Intent intent = new Intent(Main.this, TestResults.class);
startActivity(intent);
}
}
});
toolsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Main.this, Tools.class);
startActivity(intent);
}
});
}
}
这是使缓存大小达到13MB的缓存文件
- 启动后启动任务
- 您的代码似乎正在将缓存加载到主线程中
- 加载部分内容,这样应用程序就不会出现问题