我在我的 android 应用程序中使用 GoogleApiClient 并在我的应用程序恢复时遇到崩溃。
代码如下所示:
MainActivity 签名:
public class MainActivity : AppCompatActivity, GoogleApiClient.IOnConnectionFailedListener, Android.Gms.Location.ILocationListener
创建时
protected override async void OnCreate(Bundle bundle)
{
App.Initialize();
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
await InitializeGoogleApis();
}
谷歌 API 初始化
private async Task InitializeGoogleApis()
{
// Construct api client and request for required api's
googleApiClientBuilder = new GoogleApiClient.Builder(this)
.AddApi(LocationServices.API)
.EnableAutoManage(this, this);
// Connect to google play services
googleApiClient = await googleApiClientBuilder
.BuildAndConnectAsync();
// Request location api and set common properties
googleLocationRequest = new LocationRequest()
.SetPriority(LocationRequest.PriorityHighAccuracy)
.SetInterval(1000)
.SetFastestInterval(1000);
// Set location changed listener
await LocationServices.FusedLocationApi.RequestLocationUpdatesAsync(googleApiClient, googleLocationRequest, this);
}
OnResume 和 OnDestroy:
protected override void OnResume()
{
base.OnResume();
}
protected override async void OnDestroy()
{
base.OnDestroy();
if (googleApiClient != null)
await LocationServices.FusedLocationApi.RemoveLocationUpdatesAsync(googleApiClient, this);
}
我打开了所有异常但没有异常描述
当我尝试恢复时,应用程序总是崩溃。当它崩溃时,它被置于后台,当我尝试再次恢复它时,它工作得很好。