在android中,我必须获取手机GPS的实时状态,所以我添加了一个侦听器以获取时间和位置距离为0的状态 但是经过一段时间(5至30分钟)后,应用崩溃并关闭了。 我该如何调试和解决问题?
if not runTheGpsListener then
begin
runTheGpsListener := true;
if not Assigned(FLocationManager) then
begin
LocationManagerService := SharedActivityContext.getSystemService(TJContext.JavaClass.LOCATION_SERVICE);
FLocationManager := TJLocationManager.Wrap((LocationManagerService as ILocalObject).GetObjectID);
if not Assigned(locationListener) then
locationListener := TLocationListener.Create(self);
FLocationManager.requestLocationUpdates(TJLocationManager.JavaClass.GPS_PROVIDER, 5,1, locationListener, TJLooper.JavaClass.getMainLooper);
end;
end;
并像这样使用侦听器
procedure TLocationListener.onLocationChanged(location: JLocation);
begin
systemCoreTime := StrToInt64( Copy(location.getTime.ToString, 1 , location.getTime.ToString.Length-3) );
TThread.Synchronize(nil,
procedure
begin
formmain.Memo1.Text := systemCoreTime.ToString;
end);
end;
update1:
我添加了一个布尔变量来一次运行监听器
还添加了Synchronize
进行更新,但没有任何变化
但又崩溃了
这是运行时日志
09-09 11:28:05.813 13766 13766 F DEBUG : #20 pc 006c30fb /data/app/com.zafar.handset-1/lib/arm/libhandset.so
09-09 11:28:05.813 13766 13766 F DEBUG : #21 pc 00331be3 /data/app/com.zafar.handset-1/oat/arm/base.odex (offset 0x327000)
09-09 11:28:08.679 640 640 W : debuggerd: resuming target 13534
09-09 11:28:08.682 816 839 I BootReceiver: Copying /data/tombstones/tombstone_01 to DropBox (SYSTEM_TOMBSTONE)
09-09 11:28:08.691 816 13771 W ActivityManager: Force finishing activity com.zafar.handset/com.embarcadero.firemonkey.FMXNativeActivity
09-09 11:28:09.345 816 832 W ActivityManager: Activity pause timeout for ActivityRecord{e947491 u0 com.zafar.handset/com.embarcadero.firemonkey.FMXNativeActivity t42 f}
09-09 11:28:09.414 685 685 E lowmemorykiller: Error writing /proc/13534/oom_score_adj; errno=22
09-09 11:28:09.515 687 711 D gralloc_ranchu: gralloc_alloc: format 1 and usage 0x333 imply creation of host color buffer
09-09 11:28:09.565 816 832 D : HostConnection::get() New Host Connection established 0x8fa6a300, tid 832
09-09 11:28:09.595 687 687 E EGL_emulation: tid 687: eglCreateSyncKHR(1451): error 0x3004 (EGL_BAD_ATTRIBUTE)
09-09 11:28:09.658 816 879 D GraphicsStats: Buffer count: 4
09-09 11:28:09.687 816 892 W InputDispatcher: channel 'b1c7f3d com.zafar.handset/com.embarcadero.firemonkey.FMXNativeActivity (server)' ~ Consumer closed input channel or an error occurred. events=0xd
09-09 11:28:09.687 816 892 E InputDispatcher: channel 'b1c7f3d com.zafar.handset/com.embarcadero.firemonkey.FMXNativeActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
09-09 11:28:09.688 816 892 W InputDispatcher: channel '77ef4fb com.zafar.handset/com.embarcadero.firemonkey.FMXNativeActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
09-09 11:28:09.688 816 892 E InputDispatcher: channel '77ef4fb com.zafar.handset/com.embarcadero.firemonkey.FMXNativeActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
09-09 11:28:09.711 816 842 W art : Long monitor contention with owner ActivityManager (832) at android.graphics.Bitmap com.android.server.wm.WindowManagerService.screenshotApplicationsInner(android.os.IBinder, int, int, int, boolean, float, android.graphics.Bitmap$Config)(WindowManagerService.java:6252) waiters=0 in void com.android.server.wm.WindowManagerService$H.handleMessage(android.os.Message) for 223ms
09-09 11:28:09.713 691 691 I Zygote : Process 13534 exited due to signal (6)
09-09 11:28:09.733 816 833 W art : Long monitor contention with owner ActivityManager (832) at android.graphics.Bitmap com.android.server.wm.WindowManagerService.screenshotApplicationsInner(android.os.IBinder, int, int, int, boolean, float, android.graphics.Bitmap$Config)(WindowManagerService.java:6252) waiters=1 in int com.android.server.wm.WindowManagerService.relayoutWindow(com.android.server.wm.Session, android.view.IWindow, int, android.view.WindowManager$LayoutParams, int, int, int, int, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.content.res.Configuration, android.view.Surface) for 216ms
09-09 11:28:09.795 816 3622 I WindowManager: WIN DEATH: Window{77ef4fb u0 com.zafar.handset/com.embarcadero.firemonkey.FMXNativeActivity}
09-09 11:28:09.795 816 3622 W InputDispatcher: Attempted to unregister already unregistered input channel '77ef4fb com.zafar.handset/com.embarcadero.firemonkey.FMXNativeActivity (server)'
09-09 11:28:09.810 816 3376 I OpenGLRenderer: Initialized EGL, version 1.4
09-09 11:28:09.811 816 3376 D OpenGLRenderer: Swap behavior 1
09-09 11:28:09.813 687 711 D gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
09-09 11:28:09.815 816 828 W art : Long monitor contention with owner ActivityManager (832) at android.graphics.Bitmap com.android.server.wm.WindowManagerService.screenshotApplicationsInner(android.os.IBinder, int, int, int, boolean, float, android.graphics.Bitmap$Config)(WindowManagerService.java:6252) waiters=4 in void com.android.server.wm.WindowState$DeathRecipient.binderDied() for 150ms
09-09 11:28:09.815 816 828 I WindowManager: WIN DEATH: Window{b1c7f3d u0 com.zafar.handset/com.embarcadero.firemonkey.FMXNativeActivity}
09-09 11:28:09.816 816 828 W InputDispatcher: Attempted to unregister already unregistered input channel 'b1c7f3d com.zafar.handset/com.embarcadero.firemonkey.FMXNativeActivity (server)'
09-09 11:28:09.818 816 828 I WindowManager: Destroying surface Surface(name=com.zafar.handset/com.embarcadero.firemonkey.FMXNativeActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.WindowManagerService.removeWindowLocked:2436 com.android.server.wm.WindowState$DeathRecipient.binderDied:1780 android.os.BinderProxy.sendDeathNotice:688 <bottom of call stack>
09-09 11:28:09.833 687 711 D gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
09-09 11:28:09.834 687 711 D gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
09-09 11:28:09.886 816 832 D gralloc_ranchu: gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
09-09 11:28:10.026 816 829 W art : Long monitor contention with owner ActivityManager (832) at void com.android.server.am.ActivityStack$ActivityStackHandler.handleMessage(android.os.Message)(ActivityStack.java:371) waiters=0 in void com.android.server.am.ActivityManagerService$AppDeathRecipient.binderDied() for 355ms
09-09 11:28:10.027 816 829 I ActivityManager: Process com.zafar.handset (pid 13534) has died
09-09 11:28:10.177 816 833 I Choreographer: Skipped 42 frames! The application may be doing too much work on its main thread.
09-09 11:28:10.340 1020 1020 W asset : Asset path /data/app/com.zafar.handset-2/base.apk is neither a directory nor file (type=1).
09-09 11:28:10.368 687 713 D gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
09-09 11:28:10.376 687 711 D gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
09-09 11:28:10.377 1020 1020 W PackageManager: Failure retrieving resources for com.zafar.handset
09-09 11:28:10.387 687 711 D gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
09-09 11:28:10.492 687 749 D gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
09-09 11:28:10.539 816 826 I art : Background partial concurrent mark sweep GC freed 10744(957KB) AllocSpace objects, 18(1944KB) LOS objects, 20% free, 15MB/19MB, paused 33.689ms total 760.433ms
09-09 11:28:10.827 687 711 D gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
09-09 11:28:10.852 1020 1042 I art : Background partial concurrent mark sweep GC freed 39803(1358KB) AllocSpace objects, 3(60KB) LOS objects, 32% free, 8MB/12MB, paused 97.535ms total 411.516ms
09-09 11:28:10.943 687 713 D gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
09-09 11:28:10.995 1377 1437 W OpenGLRenderer: Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
答案 0 :(得分:0)
问题可能是您没有正确声明LocationListener
。
以下代码段向您展示了其中的一些操作方法:
type
TLocationListener = class;
TfrmMain = class(TForm)
ToolBarLabel: TLabel;
...
private
{ Private declarations }
FLocationManager : JLocationManager;
locationListener : TLocationListener;
...
TLocationListener = class(TJavaLocal, JLocationListener)
private
[weak]
FParent : TfrmMain;
public
constructor Create(AParent : TfrmMain);
procedure onLocationChanged(location: JLocation); cdecl;
procedure onProviderDisabled(provider: JString); cdecl;
procedure onProviderEnabled(provider: JString); cdecl;
procedure onStatusChanged(provider: JString; status: Integer; extras: JBundle); cdecl;
end;
...
procedure TfrmMain.StartLocation;
var
LocationManagerService: JObject;
location : JLocation;
begin
if not Assigned(FLocationManager) then
begin
LocationManagerService := TAndroidHelper.Context.getSystemService(TJContext.JavaClass.LOCATION_SERVICE);
FLocationManager := TJLocationManager.Wrap((LocationManagerService as ILocalObject).GetObjectID);
if not Assigned(locationListener) then
locationListener := TLocationListener.Create(self);
end;
FLocationManager.requestLocationUpdates(TJLocationManager.JavaClass.GPS_PROVIDER,
Round(MINREPFREQ * 1000), 30, locationListener,
TJLooper.JavaClass.getMainLooper);
end;