Can I pass a ResolvableApiException to a new activity?2019 Community Moderator ElectionWhy is a serializable inner class not serializable?How do save an Android Activity state using save instance state?Activity restart on rotation AndroidWhy is the Android emulator so slow? How can we speed up the Android emulator?Stop EditText from gaining focus at Activity startupHow do I pass data between Activities in Android application?How to pass an object from one activity to another on AndroidActivity has leaked window that was originally addedHow to start new activity on button clickYou need to use a Theme.AppCompat theme (or descendant) with this activityTapping on a bundled notification doesn't trigger the PendingIntent
How to generate binary array whose elements with values 1 are randomly drawn
Unfrosted light bulb
Probably overheated black color SMD pads
Should I be concerned about student access to a test bank?
Is honey really a supersaturated solution? Does heating to un-crystalize redissolve it or melt it?
Asserting that Atheism and Theism are both faith based positions
Is it possible to stack the damage done by the Absorb Elements spell?
Why is there so much iron?
Would it be believable to defy demographics in a story?
Do US professors/group leaders only get a salary, but no group budget?
Practical application of matrices and determinants
Optimising a list searching algorithm
A Ri-diddley-iley Riddle
PTIJ What is the inyan of the Konami code in Uncle Moishy's song?
How are passwords stolen from companies if they only store hashes?
Turning a hard to access nut?
Can you move over difficult terrain with only 5 feet of movement?
Wrapping homogeneous Python objects
If "dar" means "to give", what does "daros" mean?
What exactly term 'companion plants' means?
In Aliens, how many people were on LV-426 before the Marines arrived?
Brake pads destroying wheels
Relation between independence and correlation of uniform random variables
Worshiping one God at a time?
Can I pass a ResolvableApiException to a new activity?
2019 Community Moderator ElectionWhy is a serializable inner class not serializable?How do save an Android Activity state using save instance state?Activity restart on rotation AndroidWhy is the Android emulator so slow? How can we speed up the Android emulator?Stop EditText from gaining focus at Activity startupHow do I pass data between Activities in Android application?How to pass an object from one activity to another on AndroidActivity has leaked window that was originally addedHow to start new activity on button clickYou need to use a Theme.AppCompat theme (or descendant) with this activityTapping on a bundled notification doesn't trigger the PendingIntent
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!
android google-play-services google-location-services
add a comment |
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!
android google-play-services google-location-services
You can probably check this SO post, the class Exception doesn't implement the Parcelable interface. Unless android is breaking some fundamental Java constructs of which I'm unaware, this means you can't put an Exception as a Parcel into a Bundle. If you want to "pass" the exception to a new Activity, just bundle up the aspects of it that you're going to need in your new Activity. Please check the code offered by the developers.
– jess
Mar 7 at 11:52
add a comment |
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!
android google-play-services google-location-services
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!
android google-play-services google-location-services
android google-play-services google-location-services
edited Mar 7 at 15:21
rstockbridge
asked Mar 6 at 22:06
rstockbridgerstockbridge
386
386
You can probably check this SO post, the class Exception doesn't implement the Parcelable interface. Unless android is breaking some fundamental Java constructs of which I'm unaware, this means you can't put an Exception as a Parcel into a Bundle. If you want to "pass" the exception to a new Activity, just bundle up the aspects of it that you're going to need in your new Activity. Please check the code offered by the developers.
– jess
Mar 7 at 11:52
add a comment |
You can probably check this SO post, the class Exception doesn't implement the Parcelable interface. Unless android is breaking some fundamental Java constructs of which I'm unaware, this means you can't put an Exception as a Parcel into a Bundle. If you want to "pass" the exception to a new Activity, just bundle up the aspects of it that you're going to need in your new Activity. Please check the code offered by the developers.
– jess
Mar 7 at 11:52
You can probably check this SO post, the class Exception doesn't implement the Parcelable interface. Unless android is breaking some fundamental Java constructs of which I'm unaware, this means you can't put an Exception as a Parcel into a Bundle. If you want to "pass" the exception to a new Activity, just bundle up the aspects of it that you're going to need in your new Activity. Please check the code offered by the developers.
– jess
Mar 7 at 11:52
You can probably check this SO post, the class Exception doesn't implement the Parcelable interface. Unless android is breaking some fundamental Java constructs of which I'm unaware, this means you can't put an Exception as a Parcel into a Bundle. If you want to "pass" the exception to a new Activity, just bundle up the aspects of it that you're going to need in your new Activity. Please check the code offered by the developers.
– jess
Mar 7 at 11:52
add a comment |
2 Answers
2
active
oldest
votes
Instead of serializing the entire exception, it looks like Status is Parcelable and that you can recreate the ResolvableApiException from a Status.
// save to bundle
extras.putParcelable(EXTRA_RESOLVABLE_EXCEPTION_STATUS, e.getStatus());
And then to retrieve you'd do the following:
// get from bundle
Status status = bundle.getParcelable(EXTRA_RESOLVABLE_EXCEPTION_STATUS); // might have to cast as Status
ResolvableApiException resolvable = new ResolvableApiException(status);
Thanks for your suggestion. Unfortunately there is nogetStatus()
method for aResolvableApiException
. I tried addinge.getStatusCode
to the bundle and then recreating first the status from the status code and then the exception from the status, but the resolution dialog never appeared, so I don't think the exception recreation worked correctly.
– rstockbridge
Mar 13 at 1:44
add a comment |
I now have a working solution!
The key is to use getResolution()
rather than startResolutionForResult()
, as described here. getResolution()
returns a pending intent, which is Parcelable and can be attached to the intent for the new activity launched when the notification is tapped:
final Intent intent = new Intent(context, NewActivity.class);
intent.putExtra(EXTRA_PENDING_INTENT, resolvable.getResolution());
I can then extract the pending intent in my new activity and launch the dialog via startIntentSenderForResult()
:
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState)
...
final PendingIntent pendingIntent = getIntent().getParcelableExtra(EXTRA_PENDING_INTENT);
try
startIntentSenderForResult(pendingIntent.getIntentSender(), RC_LOCATION_SETTINGS, null, 0, 0, 0);
catch (IntentSender.SendIntentException e)
// Ignore the error
This approach with the pending intent makes a lot more sense because it allows you to choose when to launch the resolution dialog.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55032920%2fcan-i-pass-a-resolvableapiexception-to-a-new-activity%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Instead of serializing the entire exception, it looks like Status is Parcelable and that you can recreate the ResolvableApiException from a Status.
// save to bundle
extras.putParcelable(EXTRA_RESOLVABLE_EXCEPTION_STATUS, e.getStatus());
And then to retrieve you'd do the following:
// get from bundle
Status status = bundle.getParcelable(EXTRA_RESOLVABLE_EXCEPTION_STATUS); // might have to cast as Status
ResolvableApiException resolvable = new ResolvableApiException(status);
Thanks for your suggestion. Unfortunately there is nogetStatus()
method for aResolvableApiException
. I tried addinge.getStatusCode
to the bundle and then recreating first the status from the status code and then the exception from the status, but the resolution dialog never appeared, so I don't think the exception recreation worked correctly.
– rstockbridge
Mar 13 at 1:44
add a comment |
Instead of serializing the entire exception, it looks like Status is Parcelable and that you can recreate the ResolvableApiException from a Status.
// save to bundle
extras.putParcelable(EXTRA_RESOLVABLE_EXCEPTION_STATUS, e.getStatus());
And then to retrieve you'd do the following:
// get from bundle
Status status = bundle.getParcelable(EXTRA_RESOLVABLE_EXCEPTION_STATUS); // might have to cast as Status
ResolvableApiException resolvable = new ResolvableApiException(status);
Thanks for your suggestion. Unfortunately there is nogetStatus()
method for aResolvableApiException
. I tried addinge.getStatusCode
to the bundle and then recreating first the status from the status code and then the exception from the status, but the resolution dialog never appeared, so I don't think the exception recreation worked correctly.
– rstockbridge
Mar 13 at 1:44
add a comment |
Instead of serializing the entire exception, it looks like Status is Parcelable and that you can recreate the ResolvableApiException from a Status.
// save to bundle
extras.putParcelable(EXTRA_RESOLVABLE_EXCEPTION_STATUS, e.getStatus());
And then to retrieve you'd do the following:
// get from bundle
Status status = bundle.getParcelable(EXTRA_RESOLVABLE_EXCEPTION_STATUS); // might have to cast as Status
ResolvableApiException resolvable = new ResolvableApiException(status);
Instead of serializing the entire exception, it looks like Status is Parcelable and that you can recreate the ResolvableApiException from a Status.
// save to bundle
extras.putParcelable(EXTRA_RESOLVABLE_EXCEPTION_STATUS, e.getStatus());
And then to retrieve you'd do the following:
// get from bundle
Status status = bundle.getParcelable(EXTRA_RESOLVABLE_EXCEPTION_STATUS); // might have to cast as Status
ResolvableApiException resolvable = new ResolvableApiException(status);
answered Mar 7 at 15:41
King of BananasKing of Bananas
465
465
Thanks for your suggestion. Unfortunately there is nogetStatus()
method for aResolvableApiException
. I tried addinge.getStatusCode
to the bundle and then recreating first the status from the status code and then the exception from the status, but the resolution dialog never appeared, so I don't think the exception recreation worked correctly.
– rstockbridge
Mar 13 at 1:44
add a comment |
Thanks for your suggestion. Unfortunately there is nogetStatus()
method for aResolvableApiException
. I tried addinge.getStatusCode
to the bundle and then recreating first the status from the status code and then the exception from the status, but the resolution dialog never appeared, so I don't think the exception recreation worked correctly.
– rstockbridge
Mar 13 at 1:44
Thanks for your suggestion. Unfortunately there is no
getStatus()
method for a ResolvableApiException
. I tried adding e.getStatusCode
to the bundle and then recreating first the status from the status code and then the exception from the status, but the resolution dialog never appeared, so I don't think the exception recreation worked correctly.– rstockbridge
Mar 13 at 1:44
Thanks for your suggestion. Unfortunately there is no
getStatus()
method for a ResolvableApiException
. I tried adding e.getStatusCode
to the bundle and then recreating first the status from the status code and then the exception from the status, but the resolution dialog never appeared, so I don't think the exception recreation worked correctly.– rstockbridge
Mar 13 at 1:44
add a comment |
I now have a working solution!
The key is to use getResolution()
rather than startResolutionForResult()
, as described here. getResolution()
returns a pending intent, which is Parcelable and can be attached to the intent for the new activity launched when the notification is tapped:
final Intent intent = new Intent(context, NewActivity.class);
intent.putExtra(EXTRA_PENDING_INTENT, resolvable.getResolution());
I can then extract the pending intent in my new activity and launch the dialog via startIntentSenderForResult()
:
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState)
...
final PendingIntent pendingIntent = getIntent().getParcelableExtra(EXTRA_PENDING_INTENT);
try
startIntentSenderForResult(pendingIntent.getIntentSender(), RC_LOCATION_SETTINGS, null, 0, 0, 0);
catch (IntentSender.SendIntentException e)
// Ignore the error
This approach with the pending intent makes a lot more sense because it allows you to choose when to launch the resolution dialog.
add a comment |
I now have a working solution!
The key is to use getResolution()
rather than startResolutionForResult()
, as described here. getResolution()
returns a pending intent, which is Parcelable and can be attached to the intent for the new activity launched when the notification is tapped:
final Intent intent = new Intent(context, NewActivity.class);
intent.putExtra(EXTRA_PENDING_INTENT, resolvable.getResolution());
I can then extract the pending intent in my new activity and launch the dialog via startIntentSenderForResult()
:
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState)
...
final PendingIntent pendingIntent = getIntent().getParcelableExtra(EXTRA_PENDING_INTENT);
try
startIntentSenderForResult(pendingIntent.getIntentSender(), RC_LOCATION_SETTINGS, null, 0, 0, 0);
catch (IntentSender.SendIntentException e)
// Ignore the error
This approach with the pending intent makes a lot more sense because it allows you to choose when to launch the resolution dialog.
add a comment |
I now have a working solution!
The key is to use getResolution()
rather than startResolutionForResult()
, as described here. getResolution()
returns a pending intent, which is Parcelable and can be attached to the intent for the new activity launched when the notification is tapped:
final Intent intent = new Intent(context, NewActivity.class);
intent.putExtra(EXTRA_PENDING_INTENT, resolvable.getResolution());
I can then extract the pending intent in my new activity and launch the dialog via startIntentSenderForResult()
:
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState)
...
final PendingIntent pendingIntent = getIntent().getParcelableExtra(EXTRA_PENDING_INTENT);
try
startIntentSenderForResult(pendingIntent.getIntentSender(), RC_LOCATION_SETTINGS, null, 0, 0, 0);
catch (IntentSender.SendIntentException e)
// Ignore the error
This approach with the pending intent makes a lot more sense because it allows you to choose when to launch the resolution dialog.
I now have a working solution!
The key is to use getResolution()
rather than startResolutionForResult()
, as described here. getResolution()
returns a pending intent, which is Parcelable and can be attached to the intent for the new activity launched when the notification is tapped:
final Intent intent = new Intent(context, NewActivity.class);
intent.putExtra(EXTRA_PENDING_INTENT, resolvable.getResolution());
I can then extract the pending intent in my new activity and launch the dialog via startIntentSenderForResult()
:
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState)
...
final PendingIntent pendingIntent = getIntent().getParcelableExtra(EXTRA_PENDING_INTENT);
try
startIntentSenderForResult(pendingIntent.getIntentSender(), RC_LOCATION_SETTINGS, null, 0, 0, 0);
catch (IntentSender.SendIntentException e)
// Ignore the error
This approach with the pending intent makes a lot more sense because it allows you to choose when to launch the resolution dialog.
edited Mar 13 at 16:51
answered Mar 13 at 1:59
rstockbridgerstockbridge
386
386
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55032920%2fcan-i-pass-a-resolvableapiexception-to-a-new-activity%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You can probably check this SO post, the class Exception doesn't implement the Parcelable interface. Unless android is breaking some fundamental Java constructs of which I'm unaware, this means you can't put an Exception as a Parcel into a Bundle. If you want to "pass" the exception to a new Activity, just bundle up the aspects of it that you're going to need in your new Activity. Please check the code offered by the developers.
– jess
Mar 7 at 11:52