Interaction between the back button and scroll

AlpVir

Well-Known Member
Licensed User
Longtime User
My app has a HorizzontalScrollView with two ImageView equal tiled horizontally for a total of about 10000 pixels.
If I touch "back" button of smartphone and the scroll is of HorizzontalScrollView the app exits with an error can not be remedied ("unexpected application termination").
How to solve this problem ? Should disable the back button on your smartphone. But how?
Thanks in advance
P.S.
This code does NOT work but can give an idea

B4X:
Sub HS_ScrollChanged(Position As Int)
   PrecPosition = Position
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean   
    If KeyCode = KeyCodes.KEYCODE_BACK Then
   If HS.ScrollPosition <> PrecPosition Then 
           Return True                               
   End If
    End If 
End Sub
 

AlpVir

Well-Known Member
Licensed User
Longtime User
The message that appears is in Italian language.
Interruzione imprevista dell'applicazione 360 ALP - Panorami (processo alpvir.panorami). Riprova.
translated
Application terminated unexpectedly 360 ALP - Panorami (alpvir.panorami process). Try again.

The error occurs by sliding your finger to move horizontally HorizzontalScrollView and then (very quickly) by tapping the back of the smartphone.

Here is the long log

B4X:
Installing file.
GC_CONCURRENT freed 815K, 61% free 2737K/6983K, external 2357K/2773K, paused 2ms+5ms
Starting: Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/temp.apk typ=application/vnd.android.package-archive flg=0x10000000 cmp=com.android.packageinstaller/.PackageInstallerActivity } from pid 2417
wakeWhenReadyLocked(26)
*** set_screen_state 1
Displayed com.android.packageinstaller/.PackageInstallerActivity: +4s618ms
ACTION_SCREEN_ON -- Checked by Moto
no ack
Receiver: Screen On
Start: Received action: android.intent.action.batteryprofile.SCR_ON
Algo:Run: current state --> 1Arg --> 2
Alarms:Cancel: --> android.intent.action.batteryprofile.CHK_ALRM
State transition: 1 --> 0
Algo:Run: new state is --> 0
Screen about to return, flinger = 0x20d328
property: sys.mot_settings_secure_version=4
insert notifying for content://com.motorola.android.providers.settings/settings/lock_pin_current_failed_attempts
onReceive(), received intent:android.intent.action.USER_PRESENT
Starting: Intent { dat=file:///mnt/sdcard/temp.apk cmp=com.android.packageinstaller/.InstallAppProgress (has extras) } from pid 2433
Replacing package:alpvir.panorami
GC_EXPLICIT freed 12K, 50% free 2600K/5187K, external 2357K/2773K, paused 59ms
No content provider found for: 
asec list
Size of container 2 MB 753246 bytes
asec create smdl2tmp1 2 fat {} 10094
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
/system/bin/newfs_msdos: warning, /dev/block/dm-6 is not a character device
/system/bin/newfs_msdos: Skipping mount checks
Bogus heads from kernel - setting sane value
Bogus sectors from kernel - setting sane value
/dev/block/dm-6: 4176 sectors in 522 FAT32 clusters (4096 bytes/cluster)
bps=512 spc=8 res=32 nft=2 sec=4221 mid=0xf0 spt=63 hds=64 hid=0 bspf=5 rdcl=2 infs=1 bkbs=2
Filesystem formatted OK
Created secure container smdl2tmp1 at /mnt/asec/smdl2tmp1
Created container for smdl2tmp1 at path : /mnt/asec/smdl2tmp1
asec path smdl2tmp1
Copied /mnt/sdcard/temp.apk to /mnt/asec/smdl2tmp1/pkg.apk
asec finalize smdl2tmp1
Finalized container smdl2tmp1
Unmounting smdl2tmp1 at path /mnt/asec/smdl2tmp1
Displayed com.android.packageinstaller/.InstallAppProgress: +441ms
GC_EXPLICIT freed 15K, 50% free 2608K/5187K, external 2357K/2773K, paused 39ms
GC_EXPLICIT freed 755K, 36% free 7465K/11527K, external 7012K/8568K, paused 87ms
asec unmount smdl2tmp1 force
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
No content provider found for: 
asec mount smdl2tmp1 {} 1000
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
Scanning package: /mnt/asec/smdl2tmp1/pkg.apk
asec path smdl2tmp1
GC_EXPLICIT freed 492K, 36% free 7466K/11527K, external 3958K/5559K, paused 76ms
asec unmount smdl2tmp1 force
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
asec rename smdl2tmp1 alpvir.panorami-2
Mounting container alpvir.panorami-2
asec mount alpvir.panorami-2 {} 1000
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
asec path alpvir.panorami-2
Succesfully renamed smdl2tmp1 to alpvir.panorami-2 at new path: /mnt/asec/alpvir.panorami-2
Removing non-system package:alpvir.panorami
Force stopping package alpvir.panorami uid=10108
Scanning package alpvir.panorami
Package alpvir.panorami codePath changed from /mnt/asec/alpvir.panorami-1/pkg.apk to /mnt/asec/alpvir.panorami-2/pkg.apk; Retaining data and using new
Linking native library dir for /mnt/asec/alpvir.panorami-2/pkg.apk
DexInv: --- BEGIN '/mnt/asec/alpvir.panorami-2/pkg.apk' ---
creating instr width table
DexOpt: load 32ms, verify+opt 324ms
DexInv: --- END '/mnt/asec/alpvir.panorami-2/pkg.apk' (success) ---
Force stopping package alpvir.panorami uid=10108
Code path for pkg : alpvir.panorami changing from /mnt/asec/alpvir.panorami-1/pkg.apk to /mnt/asec/alpvir.panorami-2/pkg.apk
  Services: alpvir.panorami.downloadservice
  Receivers: alpvir.panorami.downloadservice$downloadservice_BR
  Activities: alpvir.panorami.main alpvir.panorami.panorama alpvir.panorami.helphtml alpvir.panorami.scaricare
Resource path for pkg : alpvir.panorami changing from /mnt/asec/alpvir.panorami-1/pkg.apk to /mnt/asec/alpvir.panorami-2/pkg.apk
move /data/dalvik-cache/mnt@[email protected]@[email protected] -> /data/dalvik-cache/mnt@[email protected]@[email protected]
New package installed in /mnt/asec/alpvir.panorami-2/pkg.apk
Force stopping package alpvir.panorami uid=10108
onReceive() was called -w19805
removed package name :package:alpvir.panorami
saved package name :null
PackageAdded: package:alpvir.panorami
Initializing inflate state
Not removing pkg as cache is not set
GC_EXPLICIT freed 1157K, 35% free 7506K/11527K, external 3958K/5559K, paused 104ms
onReceive() was called -w19805
GC_EXPLICIT freed 146K, 36% free 7460K/11527K, external 3958K/5559K, paused 86ms
asec unmount alpvir.panorami-1 force
alpvir.panorami-1 unmount attempt 1 failed (Device or resource busy)
Not adding pkg as cache is not set
handlePackageInstalled: re-initialize providers
[RawStanzaProvidersMgr] ##### searchProvidersFromIntent
[RawStanzaProvidersMgr] no intent receivers found
setEnabledSetting(ENABLED) - would have exited here
Process com.motorola.blur.home (2847) has open file /mnt/asec/alpvir.panorami-1/pkg.apk
Trying to load lib /data/data/com.avast.android.mobilesecurity/lib/libavast-vps-interface.so 0x404e6170
Added shared lib /data/data/com.avast.android.mobilesecurity/lib/libavast-vps-interface.so 0x404e6170
No JNI_OnLoad found in /data/data/com.avast.android.mobilesecurity/lib/libavast-vps-interface.so 0x404e6170, skipping init
Total arena pages for JIT: 11
GC_FOR_MALLOC freed 639K, 57% free 2986K/6791K, external 2357K/2773K, paused 65ms
alpvir.panorami-1 unmount attempt 2 failed (Device or resource busy)
GC_CONCURRENT freed 117K, 57% free 2976K/6791K, external 2357K/2773K, paused 3ms+3ms
Process com.motorola.blur.home (2847) has open file /mnt/asec/alpvir.panorami-1/pkg.apk
alpvir.panorami-1 unmount attempt 3 failed (Device or resource busy)
Process com.motorola.blur.home (2847) has open file /mnt/asec/alpvir.panorami-1/pkg.apk
Sending SIGHUP to process 2847
Process com.motorola.blur.home (pid 2847) has died.
WIN DEATH: Window{4092cce0 com.motorola.blur.home/com.motorola.blur.home.HomeActivity paused=false}
Process 2847 terminated by signal (15)
Start proc com.motorola.blur.home for restart com.motorola.blur.home: pid=3068 uid=10010 gids={3002, 3001, 3003, 1015}
Pub com.motorola.blur.apps: com.motorola.blur.apps.AppsProvider
Pub com.android.launcher.settings: com.motorola.blur.home.WorkspaceProvider
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
NetlinkEvent::FindParam(): Parameter 'UDEV_LOG' not found
unlink /data/dalvik-cache/mnt@[email protected]@[email protected]
Forcibly destroying container alpvir.panorami-1
GC_EXPLICIT freed 636K, 36% free 7470K/11527K, external 3958K/5559K, paused 179ms
asec destroy alpvir.panorami-1 force
Starting: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=alpvir.panorami/.main } from pid 2433
Start proc alpvir.panorami for activity alpvir.panorami/.main: pid=3082 uid=10108 gids={1015, 3003}
Skipping unknown process pid 3081
Setting rotation to 1, animFlags=1
Config changed: { scale=1.0 imsi=0/0 loc=it_IT touch=3 keys=1/1/2 nav=1/1 orien=2 layout=34 uiMode=17 seq=13}
Displayed alpvir.panorami/.main: +396ms
GC_EXTERNAL_ALLOC freed 87K, 48% free 2703K/5187K, external 2763K/2773K, paused 33ms
Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@40845c08 (uid=10108 pid=3082)
Client not active, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40960018
** Activity (main) Create, isFirst = true **
ignoring event: opt_checkedchange
** Activity (main) Resume **
showStatusIcon on inactive InputConnection
GC_EXPLICIT freed 260K, 36% free 7469K/11527K, external 3958K/5559K, paused 135ms
Starting: Intent { flg=0x20000 cmp=alpvir.panorami/.panorama } from pid 3082
** Activity (main) Pause, UserClosed = false **
catching B4AUncaughtException
** Activity (panorama) Create, isFirst = true **
GC_CONCURRENT freed 1048K, 49% free 3577K/6983K, external 3097K/3638K, paused 2ms+5ms
GC_EXTERNAL_ALLOC freed 854K, 51% free 3505K/7111K, external 3233K/3638K, paused 36ms
** Activity (panorama) Resume **
Displayed alpvir.panorami/.panorama: +1s525ms
Can't open keycharmap file
Error loading keycharmap file '/data/usr/keychars/qtouch-touchscreen.kcm.bin'. hw.keyboards.65537.devname='qtouch-touchscreen'
Can't open keycharmap file
Error loading keycharmap file '/system/usr/keychars/qtouch-touchscreen.kcm.bin'. hw.keyboards.65537.devname='qtouch-touchscreen'
Can't open keycharmap file
Using default keymap: /system/usr/keychars/qwerty.kcm.bin
** Activity (panorama) Pause, UserClosed = true **
ignoring event: hs_scrollchanged
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x40018560)
FATAL EXCEPTION: main
java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@406b0258
   at android.graphics.Canvas.throwIfRecycled(Canvas.java:955)
   at android.graphics.Canvas.drawBitmap(Canvas.java:1044)
   at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:325)
   at android.view.View.draw(View.java:6865)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
   at android.view.View.draw(View.java:6986)
   at android.widget.FrameLayout.draw(FrameLayout.java:357)
   at android.widget.HorizontalScrollView.draw(HorizontalScrollView.java:1409)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
   at android.view.View.draw(View.java:6883)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
   at android.view.View.draw(View.java:6883)
   at android.widget.FrameLayout.draw(FrameLayout.java:357)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
   at android.view.View.draw(View.java:6883)
   at android.widget.FrameLayout.draw(FrameLayout.java:357)
   at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2100)
   at android.view.ViewRoot.draw(ViewRoot.java:1525)
   at android.view.ViewRoot.performTraversals(ViewRoot.java:1261)
   at android.view.ViewRoot.handleMessage(ViewRoot.java:1862)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:130)
   at android.app.ActivityThread.main(ActivityThread.java:3806)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
   at dalvik.system.NativeStart.main(Native Method)
  Force finishing activity alpvir.panorami/.main
Setting rotation to 0, animFlags=1
Config changed: { scale=1.0 imsi=0/0 loc=it_IT touch=3 keys=1/1/2 nav=1/1 orien=1 layout=34 uiMode=17 seq=14}
Activity pause timeout for HistoryRecord{407b6b00 alpvir.panorami/.main}
 Applying overlays from /system/etc/motorola/com.motorola.blur.home/defaults.xml
 Applying overlays from /system/etc/motorola/com.motorola.blur.home/defaults.xml
GC_EXTERNAL_ALLOC freed 269K, 47% free 3041K/5703K, external 2752K/2773K, paused 28ms
LoaderThread.run - starts
loadAndBindWorkspace
loadWsFromDB
GC_EXTERNAL_ALLOC freed 109K, 47% free 3065K/5703K, external 2867K/3464K, paused 46ms
GC_EXTERNAL_ALLOC freed 171K, 46% free 3105K/5703K, external 7478K/7580K, paused 94ms
Displayed com.motorola.blur.home/.HomeActivity: +1s310ms
No longer want com.google.android.apps.uploader (pid 2108): hidden #21
GC_EXTERNAL_ALLOC freed 89K, 46% free 3113K/5703K, external 7081K/7093K, paused 48ms
GC_EXTERNAL_ALLOC freed 65K, 46% free 3119K/5703K, external 7153K/7391K, paused 28ms
GC_EXPLICIT freed 201K, 36% free 7491K/11527K, external 4674K/5559K, paused 119ms
bindWorkspace
bindWorkspace - startBinding
bindWorkspace - bindHotSeats
startingBinding
bindWorkspace - bindItems
bindWorkspace - bindFolders
bindWorkspace - finishBindingIcons
bindWorkspace - bindWidget - current panel
bindWorkspace - bindOpenedFolderOnCurrentScreen
bindWorkspace - bindWidget - others panel
bindWorkspace - bindOpenedFolderOutCurrentScreen
bindWorkspace - finishBindingItems
LoaderThread.run - ends
OnReceive
getServiceState.ENABLED_STATE
UpdateWidget - currentState=ENABLED_STATE
updateButtons
OnReceive
getServiceState
getServiceState.DISABLED_STATE
UpdateWidget - currentState=DISABLED_STATE
updateButtons
OnReceive
getServiceState.ENABLED_STATE
UpdateWidget - currentState=ENABLED_STATE
updateButtons
OnReceive
getServiceState.ENABLED_STATE
UpdateWidget - currentState=ENABLED_STATE
updateButtons
finishBindingItems
GC_EXPLICIT freed 4K, 50% free 2606K/5187K, external 2357K/2773K, paused 59ms
Activity destroy timeout for HistoryRecord{407fbe78 alpvir.panorami/.panorama}
Activity destroy timeout for HistoryRecord{407b6b00 alpvir.panorami/.main}
Unknown binder error code. 0xfffffff7
Process alpvir.panorami (pid 3082) has died.
WIN DEATH: Window{40a101a0 alpvir.panorami/alpvir.panorami.main paused=false}
WIN DEATH: Window{40a1a528 alpvir.panorami/alpvir.panorami.panorama paused=false}
Got RemoteException sending setActive(false) notification to pid 3082 uid 10108
GC_EXPLICIT freed 211K, 49% free 2778K/5447K, external 3433K/3692K, paused 43ms
GC_EXPLICIT freed 11K, 49% free 2673K/5187K, external 2357K/2773K, paused 24ms
 
Last edited:
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
The construction of a small program that reproduces the error reported in this post has been easier than expected.
The entire project (including an image of 10709x600 pixels) can be downloaded from the URL
http://www.lalpinistavirtuale.it/temp/Pano_AlpVir_ERROR.zip
It takes up little more than 1 MB.
The error occurs in both the emulator and physical device.
Thanks in advance.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You forgot to mention that you are recycling the image yourself.
The best solution is to make the bitmap a process global variable and only initialize it once.

If you do want to recycle it then you can hide the scroll view:
B4X:
Sub Activity_Pause (UserClosed As Boolean)
   Dim Obj1 As Reflector
   Obj1.Target = BMP ' bmp is the unwanted Bitmap
   Obj1.RunMethod("recycle")
   HS.Visible = False
End Sub
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
Thanks Erel
I made 3 modifications set but still does not work. Is there something else I'm missing?

B4X:
Sub Process_Globals
   Dim BMP             As Bitmap                ' [1]
End Sub

Sub Globals
   Dim HS              As HorizontalScrollView 
   Dim IV1             As ImageView 
   Dim IV2             As ImageView 
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Dim intLargImmagine As Int 
   Activity.LoadLayout("Panorama")
      
    intLargImmagine=10709   ' width of image
   
   HS.Initialize (intLargImmagine*2,"HS")

   IV1.Initialize ("")
   IV2.Initialize ("")
   
   '--- setta scala 1:1 
   IV1.Gravity = Gravity.FILL 
   IV2.Gravity = Gravity.Fill
   
   Activity.AddView(HS, 0, 0 , 100%x, 100%y)
   If FirstTime Then                                        '  [2]
      BMP.Initialize (File.DirAssets,"Aiera.jpg")
   End If
   IV1.Bitmap = BMP 
    IV2.Bitmap = BMP 
   HS.Panel.AddView(IV1,0,0,intLargImmagine,600)
   ' the "+5" only serves to identify two equal images
   HS.Panel.AddView(IV2,intLargImmagine+5,0,intLargImmagine,600)
   HS.FullScroll (True)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   Dim Obj1 As Reflector
   Obj1.Target = BMP ' bmp is the unwanted Bitmap
   Obj1.RunMethod("recycle")
   HS.Visible = False                                '  [3]
End Sub
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
The solution proposed by Erel solves the problem but in reality I have more than one image, I have several dozens (of pairs).
If I will choose one and then (after) I choose another, the BMP variable always contains the first image. And this is not correct.
In other words, missing the refresh of the image. It is selected in the module "Main" and displayed in the module "Panorama".
For simplicity and for space (KB) I have posted an example which considered a single (pair) of images but I actually I have several dozens (of pairs) of images.
I hope I did understand.
Tanks Erel
 
Upvote 0
Top