私は現在 Android アプリを開発しており、起動時間を改善しようとしています。そのために、Systraceツールを使用しています。
初めてアプリを実行したとき (インストール直後)、起動に約 40 秒かかり、次のトレースが表示されます。
ご覧のとおり、 title の付いた 30 秒の薄紫色のタグがありbindApplication
ます。
この後、アプリを閉じ (最近のアクティビティからスワイプして離します)、再度開きます。今回のbindApplication
タグの長さはわずか 4 秒です。
- 最初の実行に時間がかかるのが普通かどうか知っている人はいますか?
- 改善するにはどうすればよいですか?
bindApplication
これは App メソッドの重い作業に関係していると思いますが、それonCreate
がどのように起こるかわかりません。念のため: 私の場合はonCreate
、次のライブラリを初期化します: Parse、Crashlytics、Timber、ParseFacebookUtils、Google アナリティクス。
編集:
アプリのサブクラス コードは次のとおりです。
public class MyApp extends Application {
private Tracker tracker;
@Override public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
Trace.beginSection("MyApp");
}
Fabric.with(this, new Crashlytics());
// Parse setup
Parse.enableLocalDatastore(this);
ParseObject.registerSubclass( ... );
Parse.Configuration.Builder parseConfigBuilder = new Parse.Configuration.Builder(this).applicationId(
getString(R.string.parse_application_id))
.server(getString(R.string.parse_server_url));
if (BuildConfig.DEBUG) {
// add logs
Timber.plant(new DebugTree());
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
parseConfigBuilder.addNetworkInterceptor(new ParseLogInterceptor());
}
Parse.initialize(parseConfigBuilder.build());
ParseFacebookUtils.initialize(this);
ParseInstallation.getCurrentInstallation().saveInBackground();
AnalyticsManager.getInstance().init(this);
AnalyticsManager.getInstance().debugMode(BuildConfig.DEBUG);
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().
detectAll()
.penaltyLog()
.build());
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
Trace.endSection();
}
}
/**
* Gets the default {@link Tracker} for this {@link Application}.
* @return tracker
*/
synchronized public Tracker getDefaultTracker() {
if (tracker == null) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
// To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
tracker = analytics.newTracker(R.xml.global_tracker);
}
return tracker;
}
}