Important: Please read the Qt Code of Conduct -

Qt android one activity ?

  • Hello,
    I am working on a android app using Qt and I have found that the amount of RAM consumed by the app keeps growing as we add new features (code) on the project.
    From what I have been reading on the android documentation I found that an android app is split into different activities and activities not in the foreground may be cleaned by the system .

    Since Qt android apps live in one activity ,all my code lives in one activity and my RAM consuption is growing to unacceptable levels.Is there a way I can split my app into different activities ?Or should I try to pinpoint my problems somewhere else?

    I am fairly new to the android world and I might be trying to find the problem in a wrong place.Any input will help.

    Thank you for your time.

  • Lifetime Qt Champion


    The first thing I would do is check what makes the RAM consumption go up like that. If it sky-rockets then there might be leaks or bad memory management done (of course it could also be completely legitimate)

  • @SGaist ,thanks for the reply,
    Memory leaks are most probably contributing to this problem.I run the project througH valgrind and it reported some memory leaks which I still have to learn how to backtrace and knock down.
    My app also uses lots of QStacked widgets loaded with other widgets .

    I took a minimal widget application and added code like this at the end of the constructor to kind of simulate what is happening in my app to have an idea.

    for (int i=0;i<4200;i++)
            CustomWidget * mWidget=new CustomWidget(this);

    The consumed RAM increased by 40MB on my android armeabiv7 device compared to the minimal widget app.

    The app doesn't obviously have that many stackedWidgets but I increased the number to account for the contents and data within those stacked widgets.It was designed like this to allow fast switching between pages but It looks like we need to find another way without sacrificing lots of RAM.Any thoughts or advice?

  • Lifetime Qt Champion

    How many widgets are you creating ? And are you re-creating them ? If so are you deleting the originals ?

  • The widgets are being created dynamically when the app is running ,the number is not fixed .But it is save to assume a couple of hunderds for busy users of our app.Is it possible to have an estimate of the amount of RAM consumed by the allocation of one empty Qt widget?

    Also a side note ,could you know if there is a way to know which part of the app is consuming move RAM?I read about valgrind and I can spot memory leaks but it could help to know which part of the app is swallowing my RAM so I know where to start optimizing.

    Another problem I think I have is trying to use the Qt desktop app development mindset to mobile devices .Is there a place one can learn about a few guidelines for developping android (mobile) apps using Qt ?

    Thank you for your time.

  • Lifetime Qt Champion

    You can use KDAB's GammaRay to analyze your application.

    However there's one thing that's intriguing me, why so much widgets ?

  • GammaRay is a good tool ,but I ended up using valgrind and the problem with our app was in the desing ,having tons of (some times useless) widgets in memory at the same time.We are redesigning our user interface now instead of trying to fix a bad design.The design was done using only Qt Widgets mostly because of a lack of expertise in mobile development and QML in particular.We hope QML will ease some of the troubles we came across :-)

Log in to reply