Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Actions not responding after backing out of app on Android #294

Closed
alexduckmanton opened this issue Nov 23, 2016 · 15 comments
Closed

Actions not responding after backing out of app on Android #294

alexduckmanton opened this issue Nov 23, 2016 · 15 comments
Labels

Comments

@alexduckmanton
Copy link

Hey there,

I've got some local notifications with an action running for an audio app. The actions work great when the app is running (including when in the background), but they don't seem to respond when the app's been closed. Specifically, the action should stop audio playback.

Tapping the notification itself will re-launch the app, which is fine, but tapping an action just clears the notification. The action itself fires some code in RN, which is then passed over to some native code to control playback.

So if there isn't a way to fire that RN code from an action when the app is closed, is there a way for an action to be tied directly to some native code instead?

Thanks!

@jaison-x
Copy link

Same here +1

@sticknor
Copy link

+1

@varungupta85
Copy link
Contributor

Hi, I am not sure how would the audio play if the app is completely closed. But you can definitely control some of the actions in the native code directly. It is not there in this package for obvious reasons but you can check out how are the actions handled right now and you will get a good idea of how you can achieve it if you are familiar with Java. Basically, you can add that action to the notification in the js code and then in the native code instead of firing the notification action event for such actions, handle them directly right there. HTH

@varungupta85
Copy link
Contributor

Although the ability to handle notification actions when the app is not running is still an issue which I am also having at the moment and not able to spend time to find a way to fix it. I guess we want the app to start on receiving a notification of it is not currently running and make sure that the notification actions are initialized without needing any component to be mounted. A commit from @mlambert did add such functionality but I don't have that code in my fork since it doesn't play nice with one of the packages that I am using.

@EdenGottlieb
Copy link

+1. My app suffers from this as I rely on an ongoing notification with actions, we need some sort of solution

@npomfret
Copy link
Contributor

I've had this working, there is some info in the trouble shooting guide.

You need to code your app in such a way that the RN-push-notifications PushNotification.configure.. code gets called outside of the react-native life-cycle, basically as a side effect of an import in your top level index.js file. The reason is that it seems that when android starts your app in the background from cold as a result of receiving a remote push notification, it doesn't appear to start the react-native life-cycle. So code in your app will run, but non of the componentDid/WillMount methods will get called.

It might be a significant code change to get this working. I've had to essentially create a headless js app with no react-native in it at all, then I just use react-native as a display mechanism.

@jaison-x
Copy link

Hello @npomfret,

Is this very complex? Do you have any documentation?

Thank you.

@npomfret
Copy link
Contributor

There's no documentation. But it's not necessarily complex depending on what state your application is it. It's just a bit complex to explain. It was explained to me when the PR went in here: #220

@jaison-x
Copy link

Thanks @npomfret

@EdenGottlieb
Copy link

@jaisonveneri Please let us know if you managed to get this working, because I didn't.
I added my Listener and onNotification configure outside the React Lifecycle but it doesn't seem to get called on action press. No JS seems to get called on action press. I am using an ongoing notification, if it matters

@jaison-x
Copy link

@EdenGottlieb
I have not tried anything yet. Only next week I will try something. My goal is not to open actions but to process in the background a fetch when the app is killed and receive a notification.

@joaovpmamede
Copy link

joaovpmamede commented Mar 8, 2017

@EdenGottlieb I get the notification when the app is closed and I can see that the process is started but when I click on the notification I don't get anything from onNotification.
Does the same applies to you?

Anyone has a solution for this?

@joaovpmamede
Copy link

@npomfret I've done as you told - moved my react-native-push-notification code to index.android.js - and I get the initial notification. After I click the app opens just fine but I don't get a "new" notification object, which I'd use to run some conditions.

Btw, I got everything else working - in app notifications and background notifications.

@dluksza
Copy link

dluksza commented Feb 1, 2018

I'm facing the same issue when actions on android doesn't work when app is not running (#626). I've fixed this issue and created a PR #632

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants