我在Google Play Console上收到Android Vital的性能报告,内容涉及过多的Alarm Manager唤醒:
https://developer.android.com/topic/performance/vitals/wakeup.html
我使用Google Play服务中的Location API来请求在后台进行位置更新.在报告中,它显示唤醒唤醒过多是由LocationListener的com.google.android.location.ALARM_WAKEUP_LOCATOR引起的.
导致警报的代码段下方:
private synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(context)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
mGoogleApiClient.connect();
}
/**
* Runs when a GoogleApiClient object successfully connects.
*/
@Override
public void onConnected(Bundle connectionHint) {
try {
// Set location request
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(5 * 60000);
mLocationRequest.setFastestInterval(60000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
mLocationRequest.setMaxWaitTime(30 * 60000);
// Create a pending intent to listening on location service when the update become available
Intent mIntent = new Intent(context, LocationReceiver.class); …Run Code Online (Sandbox Code Playgroud)