Curtain
Curtain

Reputation: 1972

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 time 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!

Upvotes: 0

Views: 4970

Answers (2)

vidstige
vidstige

Reputation: 13085

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.

Upvotes: 1

Rafael T
Rafael T

Reputation: 15689

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));

Upvotes: 1

Related Questions