phonegap / phonegap-plugin-local-notification

An implementation of the Web Notifications API for end-user notifications.
MIT License
38 stars 23 forks source link

Notification onClick reloads app #12

Open varepato opened 7 years ago

varepato commented 7 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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.