Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Notification onClick reloads app #12

Open
varepato opened this issue Jul 24, 2017 · 3 comments
Open

Notification onClick reloads app #12

varepato opened this issue Jul 24, 2017 · 3 comments

Comments

@varepato
Copy link

Expected Behaviour

When click on notification should go to certain state (or view).

Actual Behaviour

When clicked on notification shows a gray screen and reloads app. I can see the notification but when I click on it reloads the app or tries to load the app twice (or open the app again).

Steps to Reproduce

add $state.go('someState'); to the notification.onClick function

Platform and Version (e.g. Android 5.0 or iOS 9.2.1)

Android 5.1

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Huawei mate S

Cordova CLI version and cordova platform version

global packages:
@ionic/cli-utils : 1.5.0
Cordova CLI : 7.0.1
Gulp CLI : CLI version 3.9.1 Local version 3.9.1
Ionic CLI : 3.5.0

local packages:
@ionic/cli-plugin-cordova : 1.4.1
@ionic/cli-plugin-gulp : 1.0.2
@ionic/cli-plugin-ionic1 : 2.0.1
Cordova Platforms : android 6.1.2
Ionic Framework : unknown

System:
Node : v6.9.2
OS : Windows 10
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
npm : 3.10.9

Plugin version

phonegap-plugin-local-notification 1.0.1

Sample Code that illustrates the problem

if (“Notification” in window) {
 Notification.requestPermission(function (permission) {
   // If the user accepts, let’s create a notification
   if (permission === ‘granted’) {
     var notification = new Notification(“My title”, {
          tag: ‘message1’, 
          body: “My body” 
     }); 
     notification.onshow  = function() { console.log(‘show’); };
     notification.onclose = function() { console.log(‘close’); };
     notification.onclick = function() { $state.go('someState'); };
   }
 });
}

I followed this article https://blog.phonegap.com/release-of-phonegap-local-notification-plugin-bc7f480b6fd6

@snow-drop
Copy link

You can try editing your config.xml and add
<preference name="AndroidLaunchMode" value="singleInstance" />
By setting it to singleInstance, the app won't create another instance of it.

@macdonst
Copy link
Member

@varepato you may want to add a slight delay in your onclick handler. Other than that do you have some logs? adb logcat

@snow-drop
Copy link

snow-drop commented Jun 18, 2018

Ah. I didn't read it thoroughly and did reply after seeing the expected behavior and actual behavior. The one I mentioned above should fix it. I also have the same problem wherein when the notification is tapped/clicked, the Android OS creates another instance of the app.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

3 participants