Android Question App suddenly closes with java.lang.reflect.InvocationTargetException

phukol

Active Member
Licensed User
Longtime User
Hi guys i am using touchimageview, photopager and a bitmap which i use to make a gallery that a user and show or hide inside a loop i am using this code to generate that
B4X:
For intA = 0 To menuMain.Length - 1
            DoEvents
            If     menuMain(intA).Trim.Length > 4 Then
                Dim strPrefix As String = menuMain(intA).Trim.SubString2(menuMain(intA).Length - 4,menuMain(intA).Length)
                If strPrefix = ".jpg" Or strPrefix = ".png" Then
                   
                    Dim p As Panel
                    p.Initialize("")
                    p.Color = Colors.ARGB(100,0,0,0) 
                   
                    Dim TouchImageView1 As TouchImageView
                   
                    TouchImageView1.Initialize("TouchImageView1")
                   
                   
                    Dim Bitmap1 As Bitmap  
                    Bitmap1.InitializeMutable(Activity.Width,Activity.Height)
                    Bitmap1  =  il.loadimgSync(menuMain(intA)) 
                   

                    If Activity.Width > 480 Then
                        Log("a " & Bitmap1.IsInitialized)
                        If Bitmap1.IsInitialized = False Then
                            Bitmap1 = Null
                            Dim Bitmap1 As Bitmap  
                            Bitmap1.InitializeMutable(Activity.Width,Activity.Height)
                            Bitmap1  =  il.loadimgSync(menuMain(intA)) 
                        End If
                       
                '        Log("b " & Bitmap1.IsInitialized)
                        p.AddView(TouchImageView1, 50%x - (Bitmap1.Width/2), 20dip, 140%x, 140%y) 
                    Else
                        p.AddView(TouchImageView1,10dip, 20dip, 140%x, 140%y)
                    End If
                   
                    TouchImageView1.MinScale=0.25            '    default is 0.5
                    TouchImageView1.MaxScale=2                '    default is 1.5
                    TouchImageView1.TranslatePadding=128dip    
                    
                    'TouchImageView1.Gravity=Gravity.FILL
                    
                   
                   
                    TouchImageView1.SetBitmap(Bitmap1)
                   
                    If FirstTime Or (TouchImageViewRect.IsInitialized = False) Or (SourceImageRect.IsInitialized = False) Then
                        '    Rect parameters are: left, top, right, bottom
                        SourceImageRect.Initialize(0, 0, Bitmap1.Width, Bitmap1.Height)
                        If Activity.Width > 480 Then
                            TouchImageViewRect.Initialize(50%x - (Bitmap1.Width/2)  , 20dip, TouchImageView1.Width, TouchImageView1.Height)
                        Else
                            TouchImageViewRect.Initialize(10dip, 20dip, TouchImageView1.Width, TouchImageView1.Height)
                        End If
                    End If
                   
                     TouchImageView1.ScaleSrcRectToDestRect(SourceImageRect, TouchImageViewRect, "CENTER")    '    make string a static constant in library
                     
                    vp.AddView(p)
                End If
            End If
        Next

it is working although a bit of slow, however when i try to open and close this module for around 4 to 5 times (i use it to change the images for different customer data), my app suddenly closes without getting any error in the logs. When i view the logs without filtering, i saw that it ends in this particular error:
B4X:
** Activity (market_detail) Resume **
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.stopProgram(Shell.java:175)
    at anywheresoftware.b4a.shell.Shell.handleIncomingData(Shell.java:189)
    at anywheresoftware.b4a.shell.ShellConnector.readControlData(ShellConnector.java:204)
    at anywheresoftware.b4a.shell.ShellConnector.connect(ShellConnector.java:185)
    at anywheresoftware.b4a.shell.ShellConnector.run(ShellConnector.java:119)
    at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NullPointerException
    at manila.fun.main.killProgram(main.java:378)
    ... 8 more

What could be the culprit? as i am not that well verse in java
 

phukol

Active Member
Licensed User
Longtime User
Thank you Erel, while in release mode i get this error on my fourth try of click to run the code
B4X:
market_detail_activity_create (java line: 986)
java.lang.RuntimeException: Object should first be initialized (Bitmap).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.getWidth(CanvasWrapper.java:600)
    at manila.fun.market_detail._activity_create(market_detail.java:986)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at manila.fun.market_detail.afterFirstLayout(market_detail.java:102)
    at manila.fun.market_detail.access$000(market_detail.java:17)
    at manila.fun.market_detail$WaitForLayout.run(market_detail.java:80)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Object should first be initialized (Bitmap).

here is my code for that area. As you can see i already placed a means of capturing if my bitmap is not initialized, so i dont know why its still having errors.
B4X:
Dim Bitmap1 As Bitmap  
                    Bitmap1.InitializeMutable(Activity.Width,Activity.Height)
                    Bitmap1  =  il.loadimgSync(menuMain(intA)) 
                   

                    If Activity.Width > 480 Then 
                        If Bitmap1.IsInitialized = False Then
                            Bitmap1 = Null
                            Dim Bitmap1 As Bitmap 
                            Bitmap1.InitializeMutable(Activity.Width,Activity.Height)
                            Bitmap1  =  il.loadimgSync(menuMain(intA))
                        End If
                        
                        p.AddView(TouchImageView1, 50%x - (Bitmap1.Width/2), 20dip, 140%x, 140%y) 
                    Else
                        p.AddView(TouchImageView1,10dip, 20dip, 140%x, 140%y)
                    End If
 
Upvote 0

phukol

Active Member
Licensed User
Longtime User
Thank you Erel. I am initializing it again because after a certain number of tries, it will output the error that the Bitmap was not initialized, i am trying to use this bitmap in a loop so what i did is to declare it everytime a new photo must be displayed. il.loadimgSync is from the UniversalImageLoader library. I am using it to fetch the photo from the web and convert it to a bitmap. Actually i also updated my code to use the AcceleratedSurface library and i tried to use CreateScaledBitmap and ReduceColors function for my bitmap. I speed up my app however i am still encountering the sudden closing of my app in this particular module. i am getting this error :

B4X:
market_detail_activity_create (java line: 958)
java.lang.OutOfMemoryError
    at android.graphics.Bitmap.nativeCreate(Native Method)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:689)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:666)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:599)
    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:479)
    at flm.b4a.accelerview.ImageUtils.CreateScaledBitmap(ImageUtils.java:95)
    at manila.fun.market_detail._activity_create(market_detail.java:958)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at manila.fun.market_detail.afterFirstLayout(market_detail.java:102)
    at manila.fun.market_detail.access$000(market_detail.java:17)
    at manila.fun.market_detail$WaitForLayout.run(market_detail.java:80)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
market_detail_activity_create (java line: 958)
java.lang.OutOfMemoryError
    at android.graphics.Bitmap.nativeCreate(Native Method)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:689)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:666)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:599)
    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:479)
    at flm.b4a.accelerview.ImageUtils.CreateScaledBitmap(ImageUtils.java:95)
    at manila.fun.market_detail._activity_create(market_detail.java:958)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at manila.fun.market_detail.afterFirstLayout(market_detail.java:102)
    at manila.fun.market_detail.access$000(market_detail.java:17)
    at manila.fun.market_detail$WaitForLayout.run(market_detail.java:80)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)

I have modified my code to this
B4X:
Sub Globals
     Dim Bitmap1 As Bitmap
end sub

'set photopager
    If marketMenu.Trim.Length > 4 Then
        Dim menuMain() As String = Regex.Split(",",marketMenu)
     
        vp.Initialize("vp",True)
        vp.Color = Colors.ARGB(100,0,0,0)
        vp.Effect= vp.Effect.Accordion
        vp.FadeEnabled = True
        pnlMarketGallery.AddView(vp, 0, 0, 100%x, 100%y)
      
     
        Dim pnlLeft As Int                      
           pnlLeft =  10dip
  
        DoEvents
        showProgress(True)
        For intA = 0 To menuMain.Length - 1
            If     menuMain(intA).Trim.Length > 4 Then
                Dim strPrefix As String = menuMain(intA).Trim.SubString2(menuMain(intA).Length - 4,menuMain(intA).Length)
                If strPrefix = ".jpg" Or strPrefix = ".png" Then
                 
                    Dim p As Panel
                    p.Initialize("")
                    p.Color = Colors.ARGB(100,0,0,0)
                 
                    Dim TouchImageView1 As TouchImageView
                    TouchImageView1.Initialize("TouchImageView1")
                 
                    Bitmap1 = iu.ReduceColors( iu.CreateScaledBitmap(il.loadimgSync(menuMain(intA)), Activity.Width, Activity.Height,True) )
                  
                    p.AddView(TouchImageView1, (lblPage.Left + (lblPage.Width/2) ) - (Bitmap1.Width/4)  , 30dip, 100%x, 100%y)
                  
                    TouchImageView1.MinScale=0.25            '    default is 0.5
                    TouchImageView1.MaxScale=2                '    default is 1.5
                    TouchImageView1.TranslatePadding=128dip    '    default is 64dip
                  
                       
                    TouchImageView1.SetBitmap(Bitmap1)
                   
                    If  (SourceImageRect.IsInitialized = False) Then SourceImageRect.Initialize(0, 0, Bitmap1.Width, Bitmap1.Height)
                      
                    If (TouchImageViewRect.IsInitialized = False) Then TouchImageViewRect.Initialize(10dip, 20dip, TouchImageView1.Width, TouchImageView1.Height)
                      
                    '    if the scaling process scales the image to less than the current MinScale or more than the current MaxScale then MinScale or MaxScale will be adjusted
                    TouchImageView1.ScaleSrcRectToDestRect(SourceImageRect, TouchImageViewRect, "CENTER")    '    make string a static constant in library
                     vp.AddView(p)
                  
                     Dim pnl As Panel
                        pnl.Initialize("")
                     
                        Dim img As ImageView
                        img.Initialize("imgMenu")
                        img.Gravity = Gravity.FILL
                        img.Tag =  intCnt
                        img.Bitmap = iu.CreateScaledBitmap(Bitmap1,80dip,100dip,True)
                      
                        intCnt = intCnt +  1
                     
                        pnl.AddView(img, 0dip, 0dip, 80dip, 100dip)
                        hsvMenu.Panel.AddView(pnl,pnlLeft,2dip,110dip,110dip)
                      
                        pnlLeft = pnlLeft + 90dip  
 
                End If
            End If
        Next
        hsvMenu.Panel.Width = 20dip + (menuMain.Length * 110dip)
    End If

In my Activity_Pause i set :
B4X:
Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        s.Close
        showProgress(False)
        ManilaFun.intForm = 1
        ImageDownloader.intForm = 1
        Bitmap1 = Null
        fab = Null
        fabCall = Null
        fabMap = Null
        fabReview = Null
        fabUber = Null
        fabWaze = Null
        hsvMenu.Panel.RemoveAllViews
        vp = Null
    End If
End Sub

I have only included the relevant part but i also attached the entire code
 

Attachments

  • Market_Detail.bas
    39.5 KB · Views: 176
Upvote 0

phukol

Active Member
Licensed User
Longtime User
i also updated ImageDownloader to this and now my program (under Release mode) shows the following error, also Out of Memory
B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals
    Private cache As Map
    Private tasks As Map
    Private ongoingTasks As Map
    Public bitProgress,bitRounded  As Boolean
    Dim rsie As RSImageEffects
    Dim rsip As RSImageProcessing
    Dim iu As AS_ImageUtils
    Public intForm As Int
End Sub

Sub Service_Create
    rsip.Initialize
    tasks.Initialize
    cache.Initialize
    ongoingTasks.Initialize
  
    Dim pageReturn As Object
            Select Case intForm
                Case 2
                    pageReturn = Cinema_Info
                Case 3
                    pageReturn = Ads_Info
                Case 4
                    pageReturn = Search_Info
                Case 5
                    pageReturn = Event_Info
                Case 6
                    pageReturn = Market_Detail      
                Case 7
                    pageReturn = Movie_Info  
                Case 8
                    pageReturn = Main      
                Case 9
                    pageReturn = SignUp      
                Case 10
                    pageReturn = BookMark  
                Case 11
                    pageReturn = Register_Password  
                Case 12
                    pageReturn = Main  
                Case 13
                    pageReturn = Market_Review
                Case 14
                    pageReturn = market_review_all
                Case 15
                    pageReturn = market_review_info
                Case Else
                    pageReturn = Main_Page
            End Select
          
    CallSubDelayed2(pageReturn, "showProgress", True)
      
End Sub

Sub Service_Start (StartingIntent As Intent)
End Sub

Sub Service_Destroy
End Sub

Sub Download (ImageViewsMap As Map)
   
    For i = 0 To ImageViewsMap.Size - 1
        tasks.Put(ImageViewsMap.GetKeyAt(i), ImageViewsMap.GetValueAt(i))
        Dim link As String = ImageViewsMap.GetValueAt(i)
        If cache.ContainsKey(link) Then
            Dim iv As ImageView = ImageViewsMap.GetKeyAt(i)
            iv.SetBackgroundImage(cache.Get(link))
        Else If ongoingTasks.ContainsKey(link) = False Then
            ongoingTasks.Put(link, "")
            Dim j As HttpJob
            j.Initialize(link, Me)
            j.Download(link)
        End If
    Next
   
End Sub

Sub JobDone(Job As HttpJob)
          
            Dim pageReturn As Object
            Select Case intForm
                Case 2
                    pageReturn = Cinema_Info
                Case 3
                    pageReturn = Ads_Info
                Case 4
                    pageReturn = Search_Info
                Case 5
                    pageReturn = Event_Info
                Case 6
                    pageReturn = Market_Detail      
                Case 7
                    pageReturn = Movie_Info  
                Case 8
                    pageReturn = Main      
                Case 9
                    pageReturn = SignUp      
                Case 10
                    pageReturn = BookMark  
                Case 11
                    pageReturn = Register_Password  
                Case 12
                    pageReturn = Main  
                Case 13
                    pageReturn = Market_Review
                Case 14
                    pageReturn = market_review_all
                Case 15
                    pageReturn = market_review_info
                Case Else
                    pageReturn = Main_Page
            End Select
          
    ongoingTasks.Remove(Job.JobName)
    If Job.Success Then
        Try
            If tasks.IsInitialized Then
                Dim bmp As Bitmap = iu.ReduceColors(Job.GetBitmap)
                cache.Put(Job.JobName, bmp)
              
                For i = 0 To tasks.Size - 1
                    Dim link As String = tasks.GetValueAt(i)
                    If link = Job.JobName Then
                        Dim iv As ImageView = tasks.GetKeyAt(i)
                        If bitRounded Then
                            Dim b As Bitmap =  iu.CreateScaledBitmap( bmp ,iv.width, iv.height,True)
                            iv.Bitmap = rsie.RoundCorner(b, 10)
                        Else
                            iv.SetBackgroundImage(iu.CreateScaledBitmap(bmp, iv.Width,iv.height, True) )
                        End If
                    End If
                Next
            End If
            bmp = Null
        Catch
            bitProgress = False
            Job.Release
            bmp = Null
            CallSubDelayed2(pageReturn, "showProgress", False)
        End Try
          
    Else
        bitProgress = False
        CallSubDelayed2(pageReturn, "showProgress", False)
    End If
    Job.Release
  
    If ongoingTasks.Size <= 0 Then
        StopService("imagedownloader")
        CallSubDelayed2(pageReturn, "showProgress", False)
    End If
  
    bitProgress = False
End Sub

Sub ActivityIsPaused
    tasks.Clear
    StopService("imagedownloader")
    Dim r As Reflector
    r.RunStaticMethod("java.lang.System", "gc", Null, Null)
    r.RunStaticMethod("java.lang.System", "gc", Null, Null)
End Sub

public Sub ClearCache
    cache.Clear
    bitRounded = False
    StopService("imagedownloader")
    Dim r As Reflector
    r.RunStaticMethod("java.lang.System", "gc", Null, Null)
    r.RunStaticMethod("java.lang.System", "gc", Null, Null)
End Sub

Note that i tried using r.RunStaticMethod("java.lang.System", "gc", Null, Null) to call the Java recycler but still same error
 
Upvote 0

phukol

Active Member
Licensed User
Longtime User
Thanks Erel, can you help me out on what particular changes i can make. I already Declared my Bitmap inside Sub Globals like this (note that i am using CreateScaledBitmap from the ImageUtils library (which is according to some is better than loadBitmapSample :


B4X:
Sub Globals
    Dim Bitmap1 As Bitmap
 
End Sub

and i have changed my code for the photopager like this

B4X:
    'set photopager
    If marketMenu.Trim.Length > 4 Then
        Dim menuMain() As String = Regex.Split(",",marketMenu)
     
        vp.Initialize("vp",True)
        vp.Color = Colors.ARGB(100,0,0,0)
        vp.Effect= vp.Effect.Accordion
        vp.FadeEnabled = True
        pnlMarketGallery.AddView(vp, 0, 0, 100%x, 100%y)
      
     
        Dim pnlLeft As Int                      
           pnlLeft =  10dip
  
        DoEvents
        showProgress(True)
     
        intCnt = 0
        For intA = 0 To menuMain.Length - 1
            If     menuMain(intA).Trim.Length > 4 Then
                Dim strPrefix As String = menuMain(intA).Trim.SubString2(menuMain(intA).Length - 4,menuMain(intA).Length)
                If strPrefix = ".jpg" Or strPrefix = ".png" Then
                 
                    intCnt = intCnt + 1
                 
                    Dim p As Panel
                    p.Initialize("")
                    p.Color = Colors.ARGB(100,0,0,0)
                 
                 
                    Bitmap1 = iu.ReduceColors( iu.CreateScaledBitmap(il.loadimgSync(menuMain(intA)), Activity.Width, Activity.Height,True) )
                                               
                    SourceImageRect.Initialize(0, 0, Bitmap1.Width, Bitmap1.Height)
                    TouchImageViewRect.Initialize(10dip, 20dip, Activity.Width, Activity.Height)
                             
                     Dim TouchImageView1 As TouchImageView
                    TouchImageView1.Initialize("TouchImageView1")
                 
                    TouchImageView1.MinScale = 0.25            '    default is 0.5
                    TouchImageView1.MaxScale = 2                '    default is 1.5
                    TouchImageView1.TranslatePadding = 128dip    '    default is 64dip 
                    TouchImageView1.SetBitmap(Bitmap1)
                 
                    p.AddView(TouchImageView1, (lblPage.Left + (lblPage.Width/2) ) - (Bitmap1.Width/4)  , 30dip, 100%x, 100%y)
                    
                        '    if the scaling process scales the image to less than the current MinScale or more than the current MaxScale then MinScale or MaxScale will be adjusted
                        TouchImageView1.ScaleSrcRectToDestRect(SourceImageRect, TouchImageViewRect, "CENTER")    '    make string a static constant in library
                         vp.AddView(p)
                    
                           Dim pnl As Panel
                        pnl.Initialize("")
                     
                        Dim img As ImageView
                        img.Initialize("imgMenu")
                        img.Gravity = Gravity.FILL
                        img.Tag =  intCnt
                        img.Bitmap = iu.CreateScaledBitmap(Bitmap1,80dip,100dip,True)
                      
                        pnl.AddView(img, 0dip, 0dip, 80dip, 100dip)
                        hsvMenu.Panel.AddView(pnl,pnlLeft,2dip,110dip,110dip)
                      
                        pnlLeft = pnlLeft + 90dip  
                     
                End If
            End If
        Next
        Starter.intTmpCnt = intCnt
        hsvMenu.Panel.Width = 20dip + (menuMain.Length * 110dip)
    End If

my ImageDownloader is like this :
B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals
    Private cache As Map
    Private tasks As Map
    Private ongoingTasks As Map
    Public bitProgress,bitRounded  As Boolean
    Dim rsie As RSImageEffects
    Dim iu As AS_ImageUtils
    Public intForm As Int
End Sub

Sub Service_Create
    tasks.Initialize
    cache.Initialize
    ongoingTasks.Initialize
 
    Dim pageReturn As Object
            Select Case intForm
                Case 2
                    pageReturn = Cinema_Info
                Case 3
                    pageReturn = Ads_Info
                Case 4
                    pageReturn = Search_Info
                Case 5
                    pageReturn = Event_Info
                Case 6
                    pageReturn = Market_Detail     
                Case 7
                    pageReturn = Movie_Info 
                Case 8
                    pageReturn = Main     
                Case 9
                    pageReturn = SignUp     
                Case 10
                    pageReturn = BookMark 
                Case 11
                    pageReturn = Register_Password 
                Case 12
                    pageReturn = Main 
                Case 13
                    pageReturn = Market_Review
                Case 14
                    pageReturn = market_review_all
                Case 15
                    pageReturn = market_review_info
                Case Else
                    pageReturn = Main_Page
            End Select
         
    CallSubDelayed2(pageReturn, "showProgress", True)
     
End Sub

Sub Service_Start (StartingIntent As Intent)
End Sub

Sub Service_Destroy
    iu = Null
    rsie = Null
End Sub

Sub Download (ImageViewsMap As Map)
  
    For i = 0 To ImageViewsMap.Size - 1
        tasks.Put(ImageViewsMap.GetKeyAt(i), ImageViewsMap.GetValueAt(i))
        Dim link As String = ImageViewsMap.GetValueAt(i)
        If cache.ContainsKey(link) Then
            Dim iv As ImageView = ImageViewsMap.GetKeyAt(i)
            iv.SetBackgroundImage( iu.CreateScaledBitmap( iu.ReduceColors( cache.Get(link) ) ,iv.Width,iv.Height,True) )
        Else If ongoingTasks.ContainsKey(link) = False Then
            ongoingTasks.Put(link, "")
            Dim j As HttpJob
            j.Initialize(link, Me)
            j.Download(link)
        End If
    Next
  
End Sub

Sub JobDone(Job As HttpJob)
         
            Dim pageReturn As Object
            Select Case intForm
                Case 2
                    pageReturn = Cinema_Info
                Case 3
                    pageReturn = Ads_Info
                Case 4
                    pageReturn = Search_Info
                Case 5
                    pageReturn = Event_Info
                Case 6
                    pageReturn = Market_Detail     
                Case 7
                    pageReturn = Movie_Info 
                Case 8
                    pageReturn = Main     
                Case 9
                    pageReturn = SignUp     
                Case 10
                    pageReturn = BookMark 
                Case 11
                    pageReturn = Register_Password 
                Case 12
                    pageReturn = Main 
                Case 13
                    pageReturn = Market_Review
                Case 14
                    pageReturn = market_review_all
                Case 15
                    pageReturn = market_review_info
                Case Else
                    pageReturn = Main_Page
            End Select
         
    ongoingTasks.Remove(Job.JobName)
    If Job.Success Then
        Try
            If tasks.IsInitialized Then
                Dim bmp As Bitmap = iu.ReduceColors(Job.GetBitmap)
                cache.Put(Job.JobName, bmp)
             
                For i = 0 To tasks.Size - 1
                    Dim link As String = tasks.GetValueAt(i)
                    If link = Job.JobName Then
                        Dim iv As ImageView = tasks.GetKeyAt(i)
                        If bitRounded Then
                            Dim b As Bitmap =  iu.CreateScaledBitmap( bmp ,iv.width, iv.height,True)
                            iv.Bitmap = rsie.RoundCorner(b, 10)
                            b = Null
                        Else
                            iv.SetBackgroundImage(iu.CreateScaledBitmap(bmp, iv.Width,iv.height, True) )
                        End If
                    End If
                Next
            End If
            bmp = Null
        Catch
            bitProgress = False
            Job.Release
            bmp = Null
            CallSubDelayed2(pageReturn, "showProgress", False)
        End Try
         
    Else
        bitProgress = False
        CallSubDelayed2(pageReturn, "showProgress", False)
    End If
    Job.Release
 
    If ongoingTasks.Size <= 0 Then
        StopService("imagedownloader")
        CallSubDelayed2(pageReturn, "showProgress", False)
    End If
 
    bitProgress = False
End Sub

Sub ActivityIsPaused
    tasks.Clear
 
End Sub

public Sub ClearCache
    cache.Clear
    bitRounded = False
 
    StopService("imagedownloader")
End Sub

can anyone help me out. im already OutOf Memory myself. Can anyone help me try to find a better approach in this.
 
Last edited:
Upvote 0

phukol

Active Member
Licensed User
Longtime User
This is what i did so far, i tried to Declare 2 bitmaps inside Starter class and i reused them in my code. I also set the heap of my app to large. So far im not experiencing any OutOfMemory errors when clicking the app to load my images. If i turn off largeheap, after about 20 to 30 tries, i am experiencing this issue
 
Upvote 0
Top