Question

I have an app which has quite a lot of activities, and all of the activities' layout have lots of views (TextViews, to display different kind of data in different styles, ImageViews etc).

When the activities load, they take too much time to load the layout/UI (more than a second).

Ques: Is there a way to reduce the time it takes to load the activity, because the activity takes too long to load the UI?

A short description of what I have:

  • All the layouts have at least 30-35 views
  • I am using Relative Layout
  • I am not nesting layouts, most of the views are parallel to each other, and the overdraw is at max 2x
  • All of the text views are custom, setting a custom font for them
  • The UI is being loaded in onCreate() of the activity

I am thinking of doing either of the following things:

  • Converting the app into Fragments in a way there are less number of activities, and more number of fragments. For example, there is one Home Activity which loads the first fragment, and further interactions with the app keep loading/switching between fragments for different purposes via Fragment Transactions. I would spawn a new activity only when I am hitting a limitation of Fragments.
    Will it help improve the speed?

  • Disintegrate the UI in a way were the most basic UI is loaded in the view once the activity starts, and all the other UI elements are inflated in a background thread (AsyncTask) and are then added to the root of the current view.

In different opinions, which approach would be better?
Is there a better or standard way of solving this problem?

Appreciating all the inputs. Thanks in advance!

Was it helpful?

Solution

Here are some more suggestions to what you've already going to do.

  1. If you inject views in onCreate() method, make sure you use design-time injection frameworks (Bufferknife or AndroidAnnotations) and not runtime ones (Guice, RoboGuice). Runtime frameworks definitely slow startup time down.

  2. If you have views, which are not visible to the user initially, you can use ViewStub and load them on demand.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top