Android 将ConnectionResult设置为可打包或可序列化的对象
我们可以将一个可包裹或可序列化的对象附加到发送给其他活动的意图,如下所示 意向。额外交付(字符串,可包裹) 我想发送,但我看到ConnectionResult既不可打包也不可序列化。我不想使用任何静态字段Android 将ConnectionResult设置为可打包或可序列化的对象,android,android-intent,android-location,Android,Android Intent,Android Location,我们可以将一个可包裹或可序列化的对象附加到发送给其他活动的意图,如下所示 意向。额外交付(字符串,可包裹) 我想发送,但我看到ConnectionResult既不可打包也不可序列化。我不想使用任何静态字段 有没有办法使此ConnectionResult可打包或可序列化?ConnectionResult不可打包,但它有一个接受错误代码和挂起内容的构造函数。这两个都是可包裹的 因此,在您的服务中: private void notifyUiFailedConnection(ConnectionRes
有没有办法使此ConnectionResult可打包或可序列化?ConnectionResult不可打包,但它有一个接受错误代码和挂起内容的构造函数。这两个都是可包裹的 因此,在您的服务中:
private void notifyUiFailedConnection(ConnectionResult result) {
Intent intent = new Intent(FIT_NOTIFY_INTENT);
intent.putExtra(FIT_EXTRA_NOTIFY_FAILED_STATUS_CODE, result.getErrorCode());
intent.putExtra(FIT_EXTRA_NOTIFY_FAILED_INTENT, result.getResolution());
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
在您的活动中:
private BroadcastReceiver mFitStatusReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// Get extra data included in the Intent
if (intent.hasExtra(GoogleFitService.FIT_EXTRA_NOTIFY_FAILED_STATUS_CODE) &&
intent.hasExtra(GoogleFitService.FIT_EXTRA_NOTIFY_FAILED_STATUS_CODE)) {
//Recreate the connection result
int statusCode = intent.getIntExtra(GoogleFitService.FIT_EXTRA_NOTIFY_FAILED_STATUS_CODE, 0);
PendingIntent pendingIntent = intent.getParcelableExtra(GoogleFitService.FIT_EXTRA_NOTIFY_FAILED_INTENT);
ConnectionResult result = new ConnectionResult(statusCode, pendingIntent);
fitHandleFailedConnection(result);
}
}
};