Activity loading too slow,

Put your problem here if it does not fit any of the other categories.

Activity loading too slow,

Postby nioupy » Sat Jan 22, 2011 9:57 pm

Hi,

I have a bit of an issue now : I have an application that takes "ages" to load new activities. By ages, I mean that when I start an intent with the subactivity, it can take 5 seconds to load it.

At first, I thought my code was badly written, so I ended up comenting everything, keeping only the setContentView() . Yet, here again, 5 seconds black screen prior to my layout.

My code is as below :
Code: Select all
                    Intent mainIntent = new Intent(Splash.this,main.class);
                    Splash.this.startActivity(mainIntent);


and the sub activity :

Code: Select all
    @Override
    public void onCreate(Bundle savedInstanceState) {     
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);       


As I suppose it 'll matter, my main layout is below:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/main"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:layout_margin="0px"
   android:padding="0px"
   android:background="@drawable/bg_geek"
>


   <LinearLayout
      android:id="@+id/Header"
      android:layout_height="wrap_content"
      android:layout_width="fill_parent"
      android:layout_alignParentTop="true"
   >
   
   </LinearLayout>

   <LinearLayout
      android:id="@+id/Footer"
      android:layout_height="wrap_content"
      android:layout_width="fill_parent"
      android:layout_alignParentBottom="true"
   >
   
   </LinearLayout>
   <LinearLayout
      android:id="@+id/MainContent"
      android:layout_below="@+id/Header"
      android:layout_above="@+id/Footer"
      android:layout_height="fill_parent"
      android:layout_width="fill_parent"
      android:orientation="vertical"
   >
   </LinearLayout>            
</RelativeLayout>


At a later stage, the views will be inflated, but right now, it's way to slow for my needs.
Do you guys see what I do wrong, any reason of the issue ? (noticed on the emulator, a dell streak and a desire) ?

Thanks in advance for any piece of advice,
nico
nioupy
Developer
Developer
 
Posts: 36
Joined: Sat Apr 03, 2010 1:34 pm

Top

Re: Activity loading too slow,

Postby Jems » Sat Jan 22, 2011 10:31 pm

Adding in lots of nested layouts can make it take much longer to inflate the layout, but that probably isn't the problem here. What happens if you just use some really simple layout as the setContentView argument, like a single TextView?
Other problems may be caused by what you have done with ids: You only need to use the + sign once when assigning an id, this indicates you have created a new id to be added to R.java file, after that just refer to it without the + sign. e.g.

android:layout_below="@id/Header"
android:layout_above="@id/Footer"
Jems
Experienced Developer
Experienced Developer
 
Posts: 57
Joined: Thu Dec 09, 2010 7:42 pm

Re: Activity loading too slow,

Postby nioupy » Sun Jan 23, 2011 8:27 am

Thanks Jems, you were right, the problem was not there but at least, you helped me correct a bad habit with the @+id

In fact, you could never have guessed it with the bits of code I gave you, but I was starting a sub activity for result, with a bit of lenghty code there.
By adding some log.d in my code, I noticed that the on result method was called straight on the start of my sub activity. I'll have to read a bit more the doc here, that wasn't the way I understood the use of it ;)

Any way, I still have a good second of slowness, but I am on the way to solve it :)

Thanks again for your suggestion :)

nico
nioupy
Developer
Developer
 
Posts: 36
Joined: Sat Apr 03, 2010 1:34 pm

Re: Activity loading too slow,

Postby Aseriesofsmallprojects » Sat Apr 02, 2011 4:50 am

Thanks from me as well, I had a few extra +id instances floating around, so now I know where it should and shouldn't be. I've been tracking down slow start-up issues as well, so ever bit of cleanup is good.
www.ProjectJourneyman.com - Android development and app marketing
twitter.com/PrjJourneyman Twitter feed
Android Developer Tutorial A growing tutorial for Android Devs
The Android Income Series Books on income topics for Android developers
Aseriesofsmallprojects
Developer
Developer
 
Posts: 39
Joined: Fri Oct 08, 2010 4:29 pm
Location: USA

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests