我有一个在地图上显示用户位置的应用程序。在物理 Nexus One上的API16、19、21、23 和 API10 上一切正常,但是当我在 Genymotion API10 模拟器上运行它时,模拟器在我调用时会重新启动
mMap.setMyLocationEnabled(true);
(本文底部的完整示例活动课程)
模拟器在没有任何事先通知的情况下重新启动,这是日志的输出:
05-26 20:36:02.944 14384-14441/com.google.android.gms.persistent E/LocationManager: locationCallbackFinished: RemoteException
android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.location.ILocationManager$Stub$Proxy.locationCallbackFinished(ILocationManager.java:763)
at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:244)
at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:160)
at android.location.LocationManager$ListenerTransport$2.handleMessage(LocationManager.java:183)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.os.HandlerThread.run(HandlerThread.java:60)
05-26 20:36:02.944 14384-14441/com.google.android.gms.persistent E/LocationManager: locationCallbackFinished: RemoteException
android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.location.ILocationManager$Stub$Proxy.locationCallbackFinished(ILocationManager.java:763)
at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:244)
at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:160)
at android.location.LocationManager$ListenerTransport$2.handleMessage(LocationManager.java:183)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.os.HandlerThread.run(HandlerThread.java:60)
05-26 20:36:02.944 14384-14441/com.google.android.gms.persistent E/LocationManager: locationCallbackFinished: RemoteException
android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.location.ILocationManager$Stub$Proxy.locationCallbackFinished(ILocationManager.java:763)
at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:244)
at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:160)
at android.location.LocationManager$ListenerTransport$2.handleMessage(LocationManager.java:183)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.os.HandlerThread.run(HandlerThread.java:60)
05-26 20:36:02.952 123-123/? E/installd: eof
05-26 20:36:02.952 123-123/? E/installd: failed to read size
05-26 20:36:03.092 14223-14223/com.google.process.gapps E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Package manager has died
at android.app.ContextImpl$ApplicationPackageManager.getApplicationInfo(ContextImpl.java:1841)
at odk.b(SourceFile:159)
at ocv.a(SourceFile:826)
at ocw.handleMessage(SourceFile:13053)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
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)
Caused by: android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.content.pm.IPackageManager$Stub$Proxy.getApplicationInfo(IPackageManager.java:1264)
at android.app.ContextImpl$ApplicationPackageManager.getApplicationInfo(ContextImpl.java:1836)
at odk.b(SourceFile:159)
at ocv.a(SourceFile:826)
at ocw.handleMessage(SourceFile:13053)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
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)
05-26 20:36:03.096 14468-14842/com.google.android.gms E/ActivityThread: Failed to find provider info for com.google.android.gsf.gservices
05-26 20:36:03.104 14468-14842/com.google.android.gms E/ActivityThread: Failed to find provider info for com.google.android.gsf.gservices
05-26 20:36:03.104 14468-14842/com.google.android.gms E/ActivityThread: Failed to find provider info for com.google.android.gsf.gservices
05-26 20:36:03.112 14223-14223/? E/AndroidRuntime: Error reporting crash
android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:2547)
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:76)
at ilq.uncaughtException(SourceFile:118)
at ils.uncaughtException(SourceFile:54)
at ilm.uncaughtException(SourceFile:63)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:854)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:851)
at dalvik.system.NativeStart.main(Native Method)
05-26 20:36:03.128 14468-14842/com.google.android.gms E/ActivityThread: Failed to find provider info for com.google.android.gsf.gservices
05-26 20:36:03.128 14468-14842/com.google.android.gms E/ActivityThread: Failed to find provider info for com.google.android.gsf.gservices
05-26 20:36:03.128 14468-14842/com.google.android.gms E/AndroidRuntime: FATAL EXCEPTION: SyncAdapterThread-1
java.lang.RuntimeException: android.os.DeadObjectException
at android.accounts.AccountManager.getAccountsByType(AccountManager.java:394)
at smx.b(SourceFile:114)
at tat.a(SourceFile:40)
at ssg.a(SourceFile:447)
at ssg.a(SourceFile:189)
at ssg.a(SourceFile:91)
at jcj.onPerformSync(SourceFile:98)
at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:164)
Caused by: android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.accounts.IAccountManager$Stub$Proxy.getAccounts(IAccountManager.java:474)
at android.accounts.AccountManager.getAccountsByType(AccountManager.java:391)
at smx.b(SourceFile:114)
at tat.a(SourceFile:40)
at ssg.a(SourceFile:447)
at ssg.a(SourceFile:189)
at ssg.a(SourceFile:91)
at jcj.onPerformSync(SourceFile:98)
at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:164)
05-26 20:36:03.128 14468-14842/com.google.android.gms E/AndroidRuntime: Error reporting crash
android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:2547)
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:76)
at ilq.uncaughtException(SourceFile:118)
at ils.uncaughtException(SourceFile:54)
at ilm.uncaughtException(SourceFile:63)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:854)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:851)
05-26 20:36:03.472 14873-14947/se.miun.mawi1402.bathingsites E/Surface: Surface (identity=11) requestBuffer(1, 0, 0, 4, 00000200) returned a buffer with a null handle
05-26 20:36:03.472 14873-14947/se.miun.mawi1402.bathingsites E/Surface: getBufferLocked(1, 0, 0, 4, 00000200) failed (Out of memory)
05-26 20:36:03.472 14873-14947/se.miun.mawi1402.bathingsites E/EGL_emulation: tid 14947: swapBuffers(322): error 0x3003 (EGL_BAD_ALLOC)
05-26 20:36:03.512 14384-14441/com.google.android.gms.persistent E/LocationManager: removeUpdates: DeadObjectException
android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.location.ILocationManager$Stub$Proxy.removeUpdates(ILocationManager.java:692)
at android.location.LocationManager.removeUpdates(LocationManager.java:872)
at adka.a(SourceFile:79)
at acpn.b(SourceFile:196)
at acpk.a(SourceFile:123)
at acpo.a(SourceFile:133)
at acpk.a(SourceFile:100)
at acpv.f(SourceFile:46)
at acpi.a(SourceFile:62)
at acpv.f(SourceFile:46)
at acmw.a(SourceFile:10191)
at acmq.a(SourceFile:10117)
at ackx.a(SourceFile:95)
at acna.a(SourceFile:204)
at acoz.b(SourceFile:352)
at acoz.a(SourceFile:235)
at acof.a(SourceFile:144)
at acpd.handleMessage(SourceFile:100)
at android.os.Handler.dispatchMessage(Handler.java:99)
at adkk.dispatchMessage(SourceFile:50)
at android.os.Looper.loop(Looper.java:130)
at android.os.HandlerThread.run(HandlerThread.java:60)
05-26 20:36:03.512 14384-14441/com.google.android.gms.persistent E/LocationManager: RemoteException in unregisterGpsStatusListener:
android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.location.ILocationManager$Stub$Proxy.removeGpsStatusListener(ILocationManager.java:746)
at android.location.LocationManager.removeGpsStatusListener(LocationManager.java:1342)
at adjw.a(SourceFile:89)
at acpk.a(SourceFile:7063)
at acpv.f(SourceFile:46)
at acpi.a(SourceFile:62)
at acpv.f(SourceFile:46)
at acmw.a(SourceFile:10191)
at acmq.a(SourceFile:10117)
at ackx.a(SourceFile:95)
at acna.a(SourceFile:204)
at acoz.b(SourceFile:352)
at acoz.a(SourceFile:235)
at acof.a(SourceFile:144)
at acpd.handleMessage(SourceFile:100)
at android.os.Handler.dispatchMessage(Handler.java:99)
at adkk.dispatchMessage(SourceFile:50)
at android.os.Looper.loop(Looper.java:130)
at android.os.HandlerThread.run(HandlerThread.java:60)
05-26 20:36:03.692 14217-14217/com.android.systemui E/InputQueue-JNI: channel 'b6660528 StatusBar (client)' ~ Publisher closed input channel or an error occurred. events=0x8
05-26 20:36:03.692 14217-14217/com.android.systemui E/InputQueue-JNI: channel 'b67f7ad0 TrackingView (client)' ~ Publisher closed input channel or an error occurred. events=0x8
05-26 20:36:03.692 14217-14217/com.android.systemui E/InputQueue-JNI: channel 'b6949638 StatusBarExpanded (client)' ~ Publisher closed input channel or an error occurred. events=0x8
05-26 20:36:03.692 14218-14218/com.android.launcher E/InputQueue-JNI: channel 'b6804400 com.android.launcher/com.android.launcher2.Launcher (client)' ~ Publisher closed input channel or an error occurred. events=0x8
05-26 20:36:03.744 127-127/? E/local_gps: Can't send RMC command
05-26 20:36:03.892 14961-14961/? E/ALSALib: external/alsa_lib/src/control/control.c:902:(snd_ctl_open_noupdate) Invalid CTL AndroidOut
05-26 20:36:03.892 14961-14961/? E/ALSALib: external/alsa_lib/src/control/control.c:902:(snd_ctl_open_noupdate) Invalid CTL AndroidIn
05-26 20:36:03.896 14961-14961/? E/ALSALib: external/alsa_lib/src/pcm/pcm.c:2210:(snd_pcm_open_noupdate) Unknown PCM AndroidPlayback_Speaker_normal
05-26 20:36:03.896 14961-14961/? E/ALSALib: external/alsa_lib/src/pcm/pcm.c:2210:(snd_pcm_open_noupdate) Unknown PCM AndroidPlayback_Speaker
05-26 20:36:03.896 14961-14961/? E/ALSALib: external/alsa_lib/src/pcm/pcm.c:2210:(snd_pcm_open_noupdate) Unknown PCM AndroidPlayback
有什么办法可以防止这种情况发生吗?我显然已经在模拟器上安装了 Google Play Services 和 Google Maps,真正奇怪的是 Google Maps 应用程序似乎运行良好。
编辑
导致模拟器重新启动的完整示例活动:
public class MapsActivityExample extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, LocationListener {
private GoogleApiClient mGoogleApiClient;
private GoogleMap mMap;
private LocationRequest mLocationRequest;
private Location lastLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
// Create an instance of GoogleAPIClient, used to deal with device location
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addApi(LocationServices.API)
.build();
// Create a location request to use when we request location change updates
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(5000); // 5s
mLocationRequest.setFastestInterval(1000); // 1s
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
}
@Override
protected void onStart() {
super.onStart();
// Connect the GoogleApiClient so we can request location updates
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
super.onStop();
// Disconnect the GoogleApiClient
mGoogleApiClient.disconnect();
}
// Callback for when the map is ready
@Override
public void onMapReady(GoogleMap googleMap){
mMap = googleMap;
}
// Callback for when the GoogleAPIClient is connected
@Override
public void onConnected(Bundle connectionHint) {
// Make sure we have permission
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
return;
// Start requesting location updates
LocationServices.FusedLocationApi.requestLocationUpdates( mGoogleApiClient, mLocationRequest, this);
// Enable the MyLocation layer, which displays the device's current location on the map
if (null != mMap)
mMap.setMyLocationEnabled(true); /** <- THIS SEEMS TO BE WHAT'S CAUSING THE REBOOT **/
}
// Callback for when the GoogleAPIClient connection is suspended
@Override
public void onConnectionSuspended(int i) {}
// Callback for when the device location has changed
@Override
public void onLocationChanged(Location location) {
}
}