I am using Google Play Services to get a user's location (package com.google.android.gms:play-services-location:16.0.0
). As described here, you can prompt the user to turn on location settings if necessary via a dialog that is launched using startResolutionForResult
:
task.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if (e instanceof ResolvableApiException) {
try {
ResolvableApiException resolvable = (ResolvableApiException) e;
resolvable.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException sendEx) {
// Ignore the error.
}
}
}
However, I would like to launch this dialog in a new activity started by tapping a notification. To do so, I am trying to add the ResolvableApiException resolvable
to the intent for the new activity so I can call startResolutionForResult
inside the new activity class. Specifically, I have:
final Intent intent = new Intent(context, NewActivity.class);
final Bundle extras = new Bundle();
extras.putSerializable(EXTRA_EXCEPTION, resolvable);
intent.putExtras(extras);
I get the following error:
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.google.android.gms.common.api.ResolvableApiException)
Caused by: java.io.NotSerializableException: com.google.android.gms.common.api.Status
ResolvableApiException
ultimately inherits from Throwable
, which implements Serializable
, so I was hoping I could add resolvable
as a serializable extra. But it seems that ResolvableApiException
's Status
field is not serializable.
Any suggestions on how I can make this approach work or another approach I can use to trigger the dialog via tapping a notification? Thanks!