Android Question Download Cancel

gerardguerin

Member
Licensed User
Longtime User
I made a simple app with 2 Activity:

1. Main Activity with a button to start second activity.

2. Second Activity, start to download 9 pictures ans display it. If you press the Back/Cancel I got a error: java.lang.reflect.InvocationTargetExceptionand , App quit...

I have include the sample code if someone what to try :) and point me my error
 

Attachments

  • Cancel Download.zip
    91.5 KB · Views: 280

gerardguerin

Member
Licensed User
Longtime User
This is my log:


Error initializing map
--------- beginning of system
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (test) Create, isFirst = true **
** Activity (test) Resume **
** Service (downloadservice) Create **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
Job completed: true
Job completed: true
Job completed: true
Job completed: true
Job completed: true
** Activity (test) Pause, UserClosed = true **
sending message to waiting queue (dd_progress)
sending message to waiting queue (dd_complete)
Ignoring cancel request. http://www.humanisoft.com/test/52404296.jpg
Ignoring cancel request. http://www.humanisoft.com/test/762044399.jpg
Ignoring cancel request. http://www.humanisoft.com/test/528643595.jpg
Ignoring cancel request. http://www.humanisoft.com/test/909029749.jpg
Ignoring cancel request. http://www.humanisoft.com/test/305792120.jpg
Ignoring cancel request. http://www.humanisoft.com/test/800634350.jpg
Ignoring cancel request. http://www.humanisoft.com/test/376315579.jpg
Error occurred on line: 71 (DownloadService)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runGoodChain(Shell.java:463)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:285)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA$2.run(BA.java:338)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7237)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.io.IOException: BufferedOutputStream is closed
at java.io.BufferedOutputStream.checkNotClosed(BufferedOutputStream.java:91)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:84)
at java.io.FilterOutputStream.flush(FilterOutputStream.java:88)
at java.io.FilterOutputStream.close(FilterOutputStream.java:61)
at anywheresoftware.b4a.objects.streams.File$OutputStreamWrapper.Close(File.java:442)
at b4a.example.downloadservice._canceldownload(downloadservice.java:191)
... 14 more
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
I succeded in stopping the App during download:
B4X:
Logger connected to:  samsung GT-I9060
--------- beginning of /dev/log/main
Ignoring cancel request. http://www.humanisoft.com/test/52404296.jpg
** Activity (test) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Service (httputils2service) Destroy **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (test) Create, isFirst = true **
** Activity (test) Resume **
** Service (downloadservice) Create **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
job done
Job completed: true
job done
job done
job done
job done
job done
job done
job done
job done
Job completed: true
Job completed: true
Job completed: true
Job completed: true
Job completed: true
Job completed: true
Job completed: true
Job completed: true
** Activity (test) Pause, UserClosed = false **
** Activity (test) Resume **
Ignoring cancel request. http://www.humanisoft.com/test/762044399.jpg
Ignoring cancel request. http://www.humanisoft.com/test/528643595.jpg
Ignoring cancel request. http://www.humanisoft.com/test/909029749.jpg
Ignoring cancel request. http://www.humanisoft.com/test/305792120.jpg
Ignoring cancel request. http://www.humanisoft.com/test/800634350.jpg
Ignoring cancel request. http://www.humanisoft.com/test/376315579.jpg
Ignoring cancel request. http://www.humanisoft.com/test/655192633.jpg
Ignoring cancel request. http://www.humanisoft.com/test/188119427.jpg
Ignoring cancel request. http://www.humanisoft.com/test/52404296.jpg
** Service (downloadservice) Destroy **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (test) Create, isFirst = true **
** Activity (test) Resume **
** Service (downloadservice) Create **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
Job cancelled before downloaded started
Job cancelled before downloaded started
Job cancelled before downloaded started
Job cancelled before downloaded started
Job cancelled before downloaded started
** Activity (test) Pause, UserClosed = true **
Job cancelled before downloaded started
Job cancelled before downloaded started
Job cancelled before downloaded started
Job cancelled before downloaded started
** Activity (main) Resume **
job done
java.io.IOException: BufferedOutputStream is closed
job done
java.io.IOException: BufferedOutputStream is closed
job done
java.io.IOException: BufferedOutputStream is closed
job done
java.io.IOException: BufferedOutputStream is closed
job done
java.io.IOException: BufferedOutputStream is closed
job done
java.io.IOException: BufferedOutputStream is closed
job done
java.io.IOException: BufferedOutputStream is closed
job done
java.io.IOException: BufferedOutputStream is closed
job done
java.io.IOException: BufferedOutputStream is closed
** Activity (main) Pause, UserClosed = false **
** Activity (test) Create, isFirst = false **
sending message to waiting queue (CallSubDelayed - dd_Complete)
sending message to waiting queue (CallSubDelayed - dd_Complete)
sending message to waiting queue (CallSubDelayed - dd_Complete)
sending message to waiting queue (CallSubDelayed - dd_Complete)
sending message to waiting queue (CallSubDelayed - dd_Complete)
sending message to waiting queue (CallSubDelayed - dd_Complete)
sending message to waiting queue (CallSubDelayed - dd_Complete)
sending message to waiting queue (CallSubDelayed - dd_Complete)
sending message to waiting queue (CallSubDelayed - dd_Complete)
running waiting messages (9)
** Activity (test) Resume **
job done
job done
job done
job done
job done
job done
job done
job done
job done
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
You can see the logs from the two tests, one completed and one cancelled.
The second activity is loaded again after completion.
I never start parallel downloads. I start the first, show results, then the second and so on...
It's quite easier to control.
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
I have got the error:
B4X:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (test) Create, isFirst = true **
** Activity (test) Resume **
** Service (downloadservice) Create **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (downloadservice) Start **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
downloadservice_canceldownload (B4A line: 71)
jt.CountingStream.Close
java.io.IOException: BufferedOutputStream is closed
    at java.io.BufferedOutputStream.checkNotClosed(BufferedOutputStream.java:91)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:84)
    at java.io.FilterOutputStream.flush(FilterOutputStream.java:88)
    at java.io.FilterOutputStream.close(FilterOutputStream.java:61)
    at anywheresoftware.b4a.objects.streams.File$OutputStreamWrapper.Close(File.java:442)
    at b4a.example.downloadservice._canceldownload(downloadservice.java:193)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:996)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:198)
    at anywheresoftware.b4a.Msgbox.debugWait(Msgbox.java:157)
    at anywheresoftware.b4a.debug.Debug.wait(Debug.java:216)
    at anywheresoftware.b4a.debug.Debug.reachBP(Debug.java:362)
    at anywheresoftware.b4a.debug.Debug.ShouldStop(Debug.java:235)
    at b4a.example.downloadservice._canceldownload(downloadservice.java:173)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:996)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:5319)
    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:1102)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: java.lang.RuntimeException: java.io.IOException: BufferedOutputStream is closed
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:999)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:5319)
    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:1102)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.io.IOException: BufferedOutputStream is closed
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:216)
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:996)
    ... 9 more
Caused by: java.io.IOException: BufferedOutputStream is closed
    at java.io.BufferedOutputStream.checkNotClosed(BufferedOutputStream.java:91)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:84)
    at java.io.FilterOutputStream.flush(FilterOutputStream.java:88)
    at java.io.FilterOutputStream.close(FilterOutputStream.java:61)
    at anywheresoftware.b4a.objects.streams.File$OutputStreamWrapper.Close(File.java:442)
    at b4a.example.downloadservice._canceldownload(downloadservice.java:193)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
    ... 10 more
--------- beginning of /dev/log/system

Seems an already closed stream...
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
Found the issue:
You set callback of DD events to activity TEST. When you cancel the download the subsequent events go to a paused activity(you perform an activity.finish).
Move the launch of download and relative avents to a service, so you can close the UI and the task are able to send it's event to something responsive and ready.
If you finish an activity the events will restart it.

Ciao
Mauro
 
Upvote 0

gerardguerin

Member
Licensed User
Longtime User
Finally I found and with a minimum of code and standard libraries, I joined you with my solution if that little help.
 

Attachments

  • Cancel Download.zip
    6.3 KB · Views: 267
Upvote 0
Top