开发者

Slow startup of second activity

What should I look when my settings Activity is starting up really slow? Sometimes I get ANR keyDispatch error if it takes to long.

Should also say that I am using PreferenceActivity. The absolute first time I go into settings the delay time is really slow (about 5-10 seconds), but otherwise it goes super smooth. This does appear when I'm reinstalling the application and start the settings for another first time (so it's a first tim开发者_StackOverflow社区e thing).

Some code in my settings PreferenceActivity:

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    pref = getPreferenceManager();    

    pref.setSharedPreferencesName(LiveWallpaper.PREFERENCES);
    addPreferencesFromResource(R.xml.live);
    pref.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);

    pref.findPreference("Username").setOnPreferenceClickListener(new OnPreferenceClickListener() {          
        public boolean onPreferenceClick(Preference preference) {
                                          // Stuff...
                return true;                
            }
        }
    );
// And so on...

Basically, I want to find out where this error is located, the question is how? Can I see in LogCat WHAT it is that's causing the delay?

Thanks for any answer!


Have you tried running the TraceView to measure exactly what is taking so long? This will guide you in the right direction. It's very easy to use from within Eclipse. In the DDMS view there is a button to start using TraceView.


You cannot see delays in Logcat as far as you don't Log them yourself. in example:

long start; 
long stop;

start = System.getCurrentTimeMillis();
pref = getPreferenceManager(); 
stop = System.getCurrentTimeMillis();
Log.d("Manager: ", "Time" + (stop - start));

start = System.getCurrentTimeMillis();
pref.setSharedPreferencesName(LiveWallpaper.PREFERENCES);
stop = System.getCurrentTimeMillis();
Log.d("SetSharedPrefs: ", "Time" + (stop - start));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜