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

Android app is reloaded when I tap on local push notification #2126

Closed
react5Moon opened this issue Aug 26, 2021 · 10 comments
Closed

Android app is reloaded when I tap on local push notification #2126

react5Moon opened this issue Aug 26, 2021 · 10 comments

Comments

@react5Moon
Copy link

My react-native android app is automatic reload when open local push-notification tap when app in foreground

react-native :0.61.5
react-native-push-notification: 7.4.0

@Dallas62
Copy link
Collaborator

Hi,
Already answered, check issues.
Regards

@react5Moon
Copy link
Author

Not working that solution

@Yandamuri
Copy link

@react5Moon Is your app reloading when you tap on local notification?

@react5Moon
Copy link
Author

@react5Moon Is your app reloading when you tap on local notification?

Yes

@Yandamuri
Copy link

@react5Moon This is how I have done configuration

          PushNotification.configure({
		onRegister: function (token) { // Called when Token is generated
		
		onNotification: function (notification) { console.log("On NOTIFICATION:", notification)
			//Process notification - Called when a remote is received or opened, or local notification is opened
			notification.finish(PushNotificationIOS.FetchResult.NoData);
		}, // Called when a remote is received or opened, or local notification is opened
		onRegistrationError: function(err) { console.error(err.message, err)}, // Called when user fails to register for          
                    remote notifications.
           });

This is how I implemented local notification

 PushNotification.localNotification({
     title,
     message: body,
     playSound: true,
     soundName: "default"
  }); 

This is the change I have done to SplashScreenActivity.java

   public void run() {
        Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
        intent.putExtras(getIntent().getExtras());  // I have added this line
        startActivity(intent);
         finish();
   }

Am I missing anything here to reload the app when tapped on local notification?

@Yandamuri
Copy link

@react5Moon Can you please check my above comment?

@react5Moon
Copy link
Author

@react5Moon This is how I have done configuration

          PushNotification.configure({
		onRegister: function (token) { // Called when Token is generated
		
		onNotification: function (notification) { console.log("On NOTIFICATION:", notification)
			//Process notification - Called when a remote is received or opened, or local notification is opened
			notification.finish(PushNotificationIOS.FetchResult.NoData);
		}, // Called when a remote is received or opened, or local notification is opened
		onRegistrationError: function(err) { console.error(err.message, err)}, // Called when user fails to register for          
                    remote notifications.
           });

This is how I implemented local notification

 PushNotification.localNotification({
     title,
     message: body,
     playSound: true,
     soundName: "default"
  }); 

This is the change I have done to SplashScreenActivity.java

   public void run() {
        Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
        intent.putExtras(getIntent().getExtras());  // I have added this line
        startActivity(intent);
         finish();
   }

Am I missing anything here to reload the app when tapped on local notification?

yes It was mistake in my code. I have put some wrong condition when app come from background. and when you click on notification app will go in background. Thanks for your response.

@Yandamuri
Copy link

@react5Moon This is how I have done configuration

          PushNotification.configure({
		onRegister: function (token) { // Called when Token is generated
		
		onNotification: function (notification) { console.log("On NOTIFICATION:", notification)
			//Process notification - Called when a remote is received or opened, or local notification is opened
			notification.finish(PushNotificationIOS.FetchResult.NoData);
		}, // Called when a remote is received or opened, or local notification is opened
		onRegistrationError: function(err) { console.error(err.message, err)}, // Called when user fails to register for          
                    remote notifications.
           });

This is how I implemented local notification

 PushNotification.localNotification({
     title,
     message: body,
     playSound: true,
     soundName: "default"
  }); 

This is the change I have done to SplashScreenActivity.java

   public void run() {
        Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
        intent.putExtras(getIntent().getExtras());  // I have added this line
        startActivity(intent);
         finish();
   }

Am I missing anything here to reload the app when tapped on local notification?

yes It was mistake in my code. I have put some wrong condition when app come from background. and when you click on notification app will go in background. Thanks for your response.

I am not really sure what your were talking about in this comment. Can you please let me know what's preventing from reloading the app when tapped on foreground notification?

@Dallas62
Copy link
Collaborator

Dallas62 commented Sep 7, 2021

Hi @react5Moon
Since you do not provide any information about your configuration, I do not see any way to help you.
Take look to issues to find some information or provide a reproducible exemple.
#1806
Regards

@ilight
Copy link

ilight commented Apr 18, 2024

Sharing in case anyone is still facing the issue, I faced exact issue posted by original author @react5Moon @Yandamuri but I am using react-native-notifications library. I am not sure if this library has a patch released but this is how I resolved the issue.

My issue was - I post a local notification when Android received a remote push and app is on foreground. Clicking on it restarts the App entirely.

https://gist.github.com/ilight/be7141f45f15e39b6fccfe46ca6e3829

NOTE:- You might have to change the paths according to the library with which you are facing the issue.

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

No branches or pull requests

4 participants