问题
I have some problems in my app. I have that after I disable the regionBootstrap and close the app through System.exit(0), my app after some minutes (usually 3-4 minutes) restarts itself.
This are the Logcat lines that I found everytime my app restarts:
2018-11-24 14:54:34.883 897-1339/? V/AlarmManager: Triggering alarm #1: 2 when =969099760 package =walkenrollment.com.acc operation =*walarm*:walkenrollment.com.acc/org.altbeacon.beacon.startup.StartupBroadcastReceiver flags =0x0
2018-11-24 14:54:34.941 897-1136/? I/ActivityManager: Start proc 11637:walkenrollment.com.acc/u0a181 for broadcast walkenrollment.com.acc/org.altbeacon.beacon.startup.StartupBroadcastReceiver
2018-11-24 14:54:35.037 897-11631/? D/OnePlusSmartBoostManager: writeHotCount walkenrollment.com.acc, pid=11637
2018-11-24 14:54:35.107 11637-11637/walkenrollment.com.acc I/ollment.com.ac: The ClassLoaderContext is a special shared library.
2018-11-24 14:54:35.210 11637-11637/walkenrollment.com.acc W/ollment.com.ac: JIT profile information will not be recorded: profile file does not exits.
2018-11-24 14:54:35.211 11637-11637/walkenrollment.com.acc I/chatty: uid=10181(walkenrollment.com.acc) identical 10 lines
2018-11-24 14:54:35.212 11637-11637/walkenrollment.com.acc W/ollment.com.ac: JIT profile information will not be recorded: profile file does not exits.
2018-11-24 14:54:35.219 11637-11637/walkenrollment.com.acc I/Perf: Connecting to perf service.
2018-11-24 14:54:35.207 11637-11637/walkenrollment.com.acc W/ollment.com.acc: type=1400 audit(0.0:2234740): avc: denied { read } for name="u:object_r:vendor_iop_prop:s0" dev="tmpfs" ino=17676 scontext=u:r:untrusted_app_27:s0:c512,c768 tcontext=u:object_r:vendor_iop_prop:s0 tclass=file permissive=0
2018-11-24 14:54:35.207 11637-11637/walkenrollment.com.acc W/ollment.com.acc: type=1400 audit(0.0:2234741): avc: denied { read } for name="u:object_r:vendor_iop_prop:s0" dev="tmpfs" ino=17676 scontext=u:r:untrusted_app_27:s0:c512,c768 tcontext=u:object_r:vendor_iop_prop:s0 tclass=file permissive=0
2018-11-24 14:54:35.222 11637-11637/walkenrollment.com.acc E/libc: Access denied finding property "vendor.perf.iop_v3.enable"
2018-11-24 14:54:35.222 11637-11637/walkenrollment.com.acc E/libc: Access denied finding property "vendor.perf.iop_v3.enable.debug"
2018-11-24 14:54:35.233 11637-11637/walkenrollment.com.acc I/InstantRun: starting instant run server: is main process
2018-11-24 14:54:35.235 11637-11637/walkenrollment.com.acc V/Font: Change font:2
2018-11-24 14:54:35.242 11637-11637/walkenrollment.com.acc I/BeaconManager: BeaconManager started up on pid 11637 named 'walkenrollment.com.acc' for application package 'walkenrollment.com.acc'. isMainProcess=true
2018-11-24 14:54:35.245 11637-11637/walkenrollment.com.acc D/BeaconParser: Parsing beacon layout: m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25
2018-11-24 14:54:35.246 11637-11637/walkenrollment.com.acc D/BeaconParser: Parsing beacon layout: m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24
2018-11-24 14:54:35.247 11637-11637/walkenrollment.com.acc D/BeaconParser: Parsing beacon layout: x,s:0-1=feaa,m:2-2=20,d:3-3,d:4-5,d:6-7,d:8-11,d:12-15
What could be the cause? Is the OnePlusSmartBoostManager the root of the problem? How can I avoid that my app restarts in this way?
These are other lines from logcat few minutes before the restart:
2018-11-24 14:48:40.989 897-2922/? I/ActivityManager: Process walkenrollment.com.acc (pid 11211) has died: fore RCVR
2018-11-24 14:48:40.991 897-912/? I/WindowManager: WIN DEATH: Window{b786f1c u0 walkenrollment.com.acc/walkenrollment.com.acc.MainActivity}
2018-11-24 14:48:40.991 897-912/? W/InputDispatcher: Attempted to unregister already unregistered input channel 'b786f1c walkenrollment.com.acc/walkenrollment.com.acc.MainActivity (server)'
2018-11-24 14:51:30.213 897-1132/? D/RestartProcessManager: updateSelf : walkenrollment.com.acc, size : 30
2018-11-24 14:51:30.214 897-1132/? D/RestartProcessManager: walkenrollment.com.acc got score 0.45182973997082543 in DayDuration for duration : 16565
2018-11-24 14:51:30.214 897-1132/? D/RestartProcessManager: walkenrollment.com.acc got score 100.0 in DayLRU for LRU diff : 49716982
2018-11-24 14:51:30.214 897-1132/? D/RestartProcessManager: walkenrollment.com.acc got score 33.33333333333333 in DayLaunchTimes for launch times : 5
2018-11-24 14:51:30.215 897-1132/? D/RestartProcessManager: walkenrollment.com.acc : X : 11871.538678708397, Y : 3274.222404673991, Z : 23827.1189741647
回答1:
Once you start ranging or monitoring, the library will try to keep it going even in the background and even after an app termination. The library does this because often the OS or user will terminate the app, when memory is low or the user is done using it in the foreground.
Auto restarts are accomplished via several techniques including an AlarmManager timer of 5 minutes and a START_STICKY service flag (Android 4.3-7.x) and a 15 minute JobService (Android 8+). This allows scanning for beacons in the background to auto launch your app logic on discovery, and by default does so with minimal system resources.
The app is auto restarting because System.exit(0)
effectively crashes your app, leaving library scanning enabled.
If you don't want this to happen, you must first shut down scanning cleanly. Stop ranging and/or monitoring and then unbind from the BeaconManager (if you bound to it) or call disable() on RegionBootstrap if you used that to initiate scanning.
回答2:
I solved this issue by adding the following to my disable monitoring function.
// Disables alarm manager
mBeaconManager.setBackgroundMode(false);
if (mRegionBootstrap != null) {
mRegionBootstrap.disable();
mRegionBootstrap = null;
}
And when I enable the monitoring I set it back to true.
mBeaconManager.setBackgroundMode(true);
So my exit function is the following:
// Disables monitoring
mBeaconScannerServiceManager.disableMonitoring();
// Closes UI
finishAffinity();
// Destroys app completely after it had time to turn off services correctly
mContainerView.postDelayed(() -> System.exit(0), 2000);
来源:https://stackoverflow.com/questions/53458978/altbeacon-app-restarts-after-some-minutes