Android Question [solved] Restarting Activity if crashed (using a service)

Asim A Baki

Active Member
Licensed User
Longtime User
How I suppress the OS crash message and restart the activity if it is crashed?
I think it must be from the service, but how to do it?
 

Asim A Baki

Active Member
Licensed User
Longtime User
Tried but no error caught, please also note that the service starting my application doesn't wait until activity stop

B4X:
StartActivity (i)

so the exception handler will not work in the background process
 
Last edited:
Upvote 0

Asim A Baki

Active Member
Licensed User
Longtime User
What if the activity only is crashed, the service is still running
Can I make a check if the main activity is not running restart it?
 
Upvote 0

eps

Expert
Licensed User
Longtime User
There _must_ be log messages - trace / debug and then unfilter the logs. If there aren't you can put some in...
 
Upvote 0

Asim A Baki

Active Member
Licensed User
Longtime User
There _must_ be log messages - trace / debug and then unfilter the logs. If there aren't you can put some in...
ok here is what the log shows

B4X:
LogCat connected to: B4A-Bridge: Sony C6802-357656051416392
--------- beginning of /dev/log/main
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (service1) Create **
** Service (service1) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
Connected to B4A-Bridge (Wifi)
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:arabiansys.presenter.pro
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
VitamioVideoView1_Prepared
 
Upvote 0

Asim A Baki

Active Member
Licensed User
Longtime User
B4X:
LogCat connected to: B4A-Bridge: Sony C6802-357656051416392
--------- beginning of /dev/log/main
VitamioVideoView1_Complete
VitamioVideoView1_Prepared
VitamioVideoView1_Complete
VitamioVideoView1_Prepared
VitamioVideoView1_Complete
VitamioVideoView1_Prepared
VitamioVideoView1_Complete
VitamioVideoView1_Prepared
VitamioVideoView1_Complete
VitamioVideoView1_Prepared
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
(Main, 112) Object was already initialized. (warning #1003)
** Activity (main) Resume **

that's all the log without filter
 
Upvote 0

Asim A Baki

Active Member
Licensed User
Longtime User
Yes it already has on error logs but nothing fired when crash occur, silent crash or OS crash message
I made the STIKY service method, it solved the issue somehow but not totally, some crashes with message from the OS can't be automatically restarted
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The UI Cloud is implemented with a server and 10 real devices that run a custom version of the designer. They can run for months without any administration.

In addition to the designer there is another app that calls Service.StartForeground. This app calls StartActivity with the designer main activity every minute. If the designer is active then nothing happens. If the designer has crashed for some reason the designer is restarted.
 
Upvote 0

Asim A Baki

Active Member
Licensed User
Longtime User
I got this error with crash if do help in debug
B4X:
Installing file.
GC_CONCURRENT freed 2912K, 40% free 11845K/19532K, paused 2ms+3ms, total 24ms
GC_CONCURRENT freed 2947K, 40% free 11835K/19532K, paused 2ms+2ms, total 32ms
GC_CONCURRENT freed 2938K, 40% free 11819K/19532K, paused 2ms+2ms, total 22ms
Installing file.
GC_CONCURRENT freed 2901K, 40% free 11844K/19532K, paused 2ms+3ms, total 22ms
GC_CONCURRENT freed 2930K, 40% free 11843K/19532K, paused 2ms+2ms, total 21ms
GC_CONCURRENT freed 2954K, 40% free 11827K/19532K, paused 3ms+2ms, total 24ms
Installing file.
GC_CONCURRENT freed 2894K, 40% free 11835K/19532K, paused 3ms+3ms, total 18ms
GC_CONCURRENT freed 2914K, 40% free 11811K/19532K, paused 1ms+2ms, total 16ms
GC_CONCURRENT freed 2890K, 40% free 11835K/19532K, paused 2ms+2ms, total 19ms
GC_CONCURRENT freed 2922K, 40% free 11843K/19532K, paused 2ms+2ms, total 17ms
PackageAdded: package:arabiansys.presenter.pro
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.UnsatisfiedLinkError: Native method not found: io.vov.vitamio.MediaPlayer.unloadOMX_native:()V
    at io.vov.vitamio.MediaPlayer.unloadOMX_native(Native Method)
    at io.vov.vitamio.MediaPlayer.<init>(MediaPlayer.java:222)
    at io.vov.vitamio.widget.VideoView.openVideo(VideoView.java:408)
    at io.vov.vitamio.widget.VideoView.access$24(VideoView.java:396)
    at io.vov.vitamio.widget.VideoView$3.surfaceCreated(VideoView.java:160)
    at android.view.SurfaceView.updateWindow(SurfaceView.java:571)
    at android.view.SurfaceView.access$000(SurfaceView.java:86)
    at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175)
    at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:837)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1868)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1008)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5505)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
    at android.view.Choreographer.doFrame(Choreographer.java:532)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:213)
    at android.app.ActivityThread.main(ActivityThread.java:5225)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    at dalvik.system.NativeStart.main(Native Method)
 
Upvote 0

Asim A Baki

Active Member
Licensed User
Longtime User
and this error as well

B4X:
** Activity (main) Resume **
An error occurred:
(Line: 133) ToastMessageShow("Connecting..."  ,False)
java.lang.OutOfMemoryError: Java heap space
 
Upvote 0

Asim A Baki

Active Member
Licensed User
Longtime User
and this from google market report
B4X:
Build fingerprint: 'Sony/C6802/C6802:4.3/14.2.A.1.136/d_v_jg:user/release-keys'
Revision: '0'
pid: 10073, tid: 10160, name: s.presenter.pro >>> arabiansys.presenter.pro <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
r0 00000027 r1 71bc7038 r2 00000000 r3 deadbaad
r4 00000000 r5 790eac54 r6 00000000 r7 756edc20
r8 756edbe0 r9 750f3cf0 sl ffffffff fp 756eb020
ip 00000001 sp 790eac50 lr 400df1ab pc 400dc704 cpsr 60000030
d0 0000000000000000 d1 4090000000000000
d2 0000000000000000 d3 0000000000000000
d4 0000000000000000 d5 0000000000000000
d6 44a00000000002d0 d7 3fe38e393fe38e39
d8 0000000000000000 d9 0000000000000000
d10 0000000000000000 d11 0000000000000000
d12 0000000000000000 d13 0000000000000000
d14 0000000000000000 d15 0000000000000000
d16 0002046900019895 d17 0000d01f0000644b
d18 0000000000000000 d19 0000000000000000
d20 0000000000000000 d21 000000007605c820
d22 0000000000000000 d23 0000000000000000
d24 3d2e0aea696dec68 d25 3fe36e96cf44d320
d26 3fe67cf7864581a8 d27 bf56c086eba4cb27
d28 3fd799a28b72e08a d29 bf7921f4442d1800
d30 3fc655e270d68650 d31 3f1153165ec18a01
scr 28000012

backtrace:
#00 pc 0001e704 /system/lib/libc.so
#01 pc 0001c6f4 /system/lib/libc.so (abort+4)
#02 pc 0059e22d /data/data/arabiansys.presenter.pro/libs/libffmpeg.so (sws_setColorspaceDetails+2100)

code around pc:
400dc6e4 461ce00b 2b006823 e026d1fb b12468e4
400dc6f4 21014a18 6011447a 4b1247a0 24002027
400dc704 f7fc7018 2106ee26 e87cf7fe 5180f04f
400dc714 a9029104 94022006 9403460a ec28f7fd
400dc724 46224629 f7fd2002 f7fcec34 2106ee12
400dc734 e868f7fe f7fc2001 6960eabe d1dc2800
400dc744 bf00e7d4 deadbaad 00029914 ffffff9c
400dc754 0002cbb8 0002cb9c 2400b510 aa04b088
400dc764 46699002 94014620 94039400 eb76f7fd
400dc774 db0642a0 b1139b07 1c419806 98069106
400dc784 4620e000 bd10b008 4b1eb40e b082b5f0
400dc794 447b491d f107af00 585e021c f8522101
400dc7a4 68354b04 f852607d 31015b04 d1fa2d00
400dc7b4 320e008a 0507f022 0220f107 0d05ebad
400dc7c4 f107603a 46690224 9400466d 4c04f852
400dc7d4 f8453204 2c004f04 f8dfd1f8 f853c030

code around lr:
400df188 4a0e4b0d e92d447b 260041f0 4680589c
400df198 686768a5 f9b5e007 2b00300c 4628dd02
400df1a8 430647c0 3f013554 6824d5f5 d1ef2c00
400df1b8 e8bd4630 bf0081f0 00026e48 ffffffc4
400df1c8 43f0e92d fb01461e 4b16f502 4916460f
400df1d8 447bb087 aa014614 20019001 95029203
400df1e8 90049505 681a585b b1124698 f0094630
400df1f8 4630fd26 f7ffa903 4681fe9c 0000f8d8
400df208 4630b110 fd28f009 0f00f1b9 9c05d005
400df218 1b284639 eadef017 46204604 e8bdb007
400df228 bf0083f0 00026dfa ffffff60 46036842
400df238 60411e51 da012900 bb9ef000 f8126802
400df248 601a0b01 00004770 4a104b0f b570447b
400df258 589b4604 461e6819 f009b109 6860fcf0
400df268 60651e45 da042d00 f0004620 4605fb85
400df278 6822e003 5b01f812 68336022 4620b113
 
Upvote 0

eps

Expert
Licensed User
Longtime User
and this error as well

B4X:
** Activity (main) Resume **
An error occurred:
(Line: 133) ToastMessageShow("Connecting..."  ,False)
java.lang.OutOfMemoryError: Java heap space

For this error it looks like you ran out of memory.. I would use MemoryManager to see what the memory usage of your App is and try to optimise the memory use, then it will crash a lot less.

You can also use the LargeHeap manifest setting as well. http://www.b4x.com/android/forum/threads/using-android-largeheap.14903/#post-120731
 
Upvote 0

Asim A Baki

Active Member
Licensed User
Longtime User
Upvote 0
Top