0

I'm creating Android app which sends multiple selected images onto web database

I followed the tutorial from https://demonuts.com/select-multiple-images-gallery

The problem is that above code works well on the virtual emulator device See below image where "2 selected" and "SELECT" show up on the virtual device
enter image description here

But above parts of "2 selected" and "SELECT" don't show up on the actual phone
so that I can't move back to previous activity with selected images like following and I can't click the "send" button
enter image description here

I guess the code uses Android's built-in image selection viewer than custom xml viwer so that I can't figure out how to add "button" on that Android's built-in image selection viewer
and can't figure out where I should add "onclicklistener" with respect to that button if I can add button to Android's built-in image selection viewer

Or if there is some other way that I can implement same "multiple image selection algorithm", please suggest it in detail cause I'm new to Android development

================================================================================ Edit: The error log when I click SELECT button on the actual phone

I/art: Starting a blocking GC Alloc
    Starting a blocking GC Alloc
I/art: Alloc sticky concurrent mark sweep GC freed 4(448B) AllocSpace objects, 0(0B) LOS objects, 7% free, 89MB/96MB, paused 488us total 7.373ms
    Starting a blocking GC Alloc
I/art: Clamp target GC heap from 105MB to 96MB
    Alloc partial concurrent mark sweep GC freed 6(144B) AllocSpace objects, 0(0B) LOS objects, 7% free, 89MB/96MB, paused 511us total 26.117ms
    Starting a blocking GC Alloc
I/art: Clamp target GC heap from 105MB to 96MB
    Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 7% free, 89MB/96MB, paused 542us total 42.448ms
    Forcing collection of SoftReferences for 7MB allocation
I/art: Starting a blocking GC Alloc
I/art: Clamp target GC heap from 105MB to 96MB
    Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 7% free, 89MB/96MB, paused 533us total 42.342ms
    Starting a blocking GC HomogeneousSpaceCompact
I/art: Clamp target GC heap from 105MB to 96MB
    HomogeneousSpaceCompact marksweep + semispace GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 7% free, 89MB/96MB, paused 45.430ms total 45.430ms
W/art: Throwing OutOfMemoryError "Failed to allocate a 7784024 byte allocation with 7276856 free bytes and 6MB until OOM"
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.prototype, PID: 4943
    java.lang.OutOfMemoryError: Failed to allocate a 7784024 byte allocation with 7276856 free bytes and 6MB until OOM
        at java.lang.StringFactory.newStringFromBytes(StringFactory.java:185)
        at java.lang.StringFactory.newStringFromBytes(StringFactory.java:63)
        at android.util.Base64.encodeToString(Base64.java:456)
        at com.example.prototype.UploadMultiplePicturesActivity.imageToString(UploadMultiplePicturesActivity.java:330)
        at com.example.prototype.UploadMultiplePicturesActivity.onActivityResult(UploadMultiplePicturesActivity.java:293)
        at android.app.Activity.dispatchActivityResult(Activity.java:7028)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4217)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4264)
        at android.app.ActivityThread.-wrap20(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1602)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6351)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:896)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:786)
YoungMin Park
  • 1,101
  • 1
  • 10
  • 18
  • 1
    Is your application's theme NoActionBar? If yes then switch to actionbar and try. – Vir Rajpurohit Sep 05 '19 at 04:40
  • 1
    "But above parts of '2 selected' and 'SELECT' don't show up on the actual phone" – What does it look like on the phone? Do you have a screenshot of that? – Mike M. Sep 05 '19 at 04:45
  • @MikeM. Hi. On the actual phone, "button" shows up as "opening" button (red square) than "selection" button So, when I click the "opening" button the app crashes down raw.githubusercontent.com/youngminpark2559/test/master/img/20190905_143152.jpg – YoungMin Park Sep 05 '19 at 05:39
  • @VirRajpurohit NoActionBar, interesting idea. But if I apply "using ActionBar" through the configuration off theme, that affects entire app, for example, action bar shows up on the every pages? Anyway, I'll search it. Thanks – YoungMin Park Sep 05 '19 at 05:41
  • 1
    Well, that seems equivalent to the example's screenshot, just in a different language, yeah? So it sounds like your only problem is the crash when it returns the result to your `Activity`, right? You'll need to look at the [stack trace](https://stackoverflow.com/a/23353174) to see what's causing the crash. – Mike M. Sep 05 '19 at 05:48
  • 1
    @YoungMinPark Though it shows in all activities but it has worked? – Vir Rajpurohit Sep 05 '19 at 05:51
  • @VirRajpurohit I comment `true` from `res/values/styles.xml` but unfortunately, no changes in the bar. I think Mike M's guessing is correct. The bar looks same but when I click the select button, the app crashes and I added the error log – YoungMin Park Sep 05 '19 at 06:01
  • @MikeM. I guess your guess on the button is correct. And I added the error log. How do you think on that error log? For information, the actual device is LG X2. The storage is enough. I convert all selected bitmap image files into base64 string. Can it cause the memory overflow issue? – YoungMin Park Sep 05 '19 at 06:02
  • 7784024 byte which is mentioned from above error is just 7 mega bytes which is not a huge size which can cause memory overflow – YoungMin Park Sep 05 '19 at 06:08
  • 1
    Right, but at that point, you only have 7276856 bytes free. As for how to fix that, I can't be sure, since I don't know exactly what you're doing in the `Activity` to use up that memory. If you are displaying the selected images, make sure to sample the image appropriately, so you're not showing a 6MP image in a 100x100 `View`. Libraries like Glide or Picasso can do that automatically for you. Otherwise, `BitmapFactory` can do it, with a little work on your part. Also, don't try to convert and upload all of the selected images at once. Queue them up, so you're only doing one at a time. – Mike M. Sep 05 '19 at 06:16
  • @MikeM. Thanks for the helpful advise. I guess the error of memory overflow is caused because I convert image into base64 string on the android code (even if I'm not sure whether it's actually the reason for the error) So, I'm going to use return image itself than converting image into base64 string – YoungMin Park Sep 05 '19 at 07:25

0 Answers0