Android Question Loading Icons

treehousefrog

Member
Licensed User
Longtime User
Hey guys,

I need a little help with the launchers I'm building...

Basically I am loading a list of applications on the device into a listview with icons and am handling this in a timer. Unfortunately though, if I test this on a device that has lots of apps installed, it then causes the app to crash, presumably because it's out of memory...

Here's the code I'm using:

B4X:
bloot = packman1.GetApplicationIcon(s.Split(placer, "@").Get(1))
allapps.AddTwoLinesAndBitmap(s.Split(placer, "@").get(0), s.Split(placer, "@").Get(1), bloot.Bitmap)

Is there anything I could do to reduce the strain and prevent crashing? I know lots of other apps that load icons into a list, so there must be a way!

Thanks so much in advance guys :-D This one has been bugging me for a while now!
 

LucaMs

Expert
Licensed User
Longtime User
I tried in this way (without timer) and it does not create problem
B4X:
Sub LoadAppsListView

    Dim packages As List
    Dim AppPckgName As String
    Dim iconDrw As BitmapDrawable
    packages = pm.GetInstalledPackages
 
    ListView1.Clear
 
    For i = 0 To packages.Size - 1
        AppPckgName = packages.Get(i)
        Log(AppPckgName)
        iconDrw = pm.GetApplicationIcon(AppPckgName)
        ListView1.AddTwoLinesAndBitmap2("booo " & i, "booooo " & i, iconDrw.Bitmap, AppPckgName)
    Next
End Sub


Indeed, it has some problems: I do not have the amount of apps that it lists (many of them probably are services)
 
Last edited:
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
What is you timer's interval? Perhaps this sub is entered again during still executed. If this is the case, you should disable the timer as long as you're still processing data or set a flag to exit this sub.
 
Upvote 0

treehousefrog

Member
Licensed User
Longtime User
Hey guys,

Thanks so much for the quick responses :-D

The app simply force closes (no error message), and it tends to do it after loading around 300 icons (pretty consistently regardless of what apps are installed). I previously did it your way Lucas, but it caused the app to freeze for too long the first time it loaded and on orientation changes...

I did think something like that mc73 - could you possibly show me how to go about implementing one of those solutions? How do I find out if the app is still processing data?

Thanks again everyone!
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Have you checked the unfiltered log?
 
Upvote 0
Top