Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

App restarts when notification received. onNotification not called #846

Closed
KthProg opened this issue Aug 26, 2018 · 5 comments

Comments

Projects
None yet
1 participant
@KthProg
Copy link

commented Aug 26, 2018

When I start my application, one the first notification received the app goes to the root view. There don't appear to be any errors, it just navigates to the login for no reason. Subsequent notifications simply do nothing, including not calling the handler I have set up.

@KthProg

This comment has been minimized.

Copy link
Author

commented Aug 26, 2018

I also see things like this quite a bit: 08-26 16:57:49.933 23701 25650 W unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.uimanager.LayoutShadowNode

@KthProg

This comment has been minimized.

Copy link
Author

commented Aug 26, 2018

And I saw this but I haven't had any crashes:

08-26 16:57:49.623 23701 25649 W System.err: org.json.JSONException: No value for bundledAssets
08-26 16:57:49.623 23701 25649 W System.err: 	at org.json.JSONObject.get(JSONObject.java:389)
08-26 16:57:49.623 23701 25649 W System.err: 	at org.json.JSONObject.getJSONArray(JSONObject.java:584)
08-26 16:57:49.623 23701 25649 W System.err: 	at versioned.host.exp.exponent.modules.api.FileSystemModule.getBundledAssets(FileSystemModule.java:119)
08-26 16:57:49.624 23701 25649 W System.err: 	at versioned.host.exp.exponent.modules.api.FileSystemModule.getConstants(FileSystemModule.java:101)
08-26 16:57:49.624 23701 25649 W System.err: 	at com.facebook.react.bridge.JavaModuleWrapper.getConstants(JavaModuleWrapper.java:138)
08-26 16:57:49.624 23701 25649 W System.err: 	at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
08-26 16:57:49.624 23701 25649 W System.err: 	at android.os.Handler.handleCallback(Handler.java:751)
08-26 16:57:49.624 23701 25649 W System.err: 	at android.os.Handler.dispatchMessage(Handler.java:95)
08-26 16:57:49.624 23701 25649 W System.err: 	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
08-26 16:57:49.624 23701 25649 W System.err: 	at android.os.Looper.loop(Looper.java:154)
08-26 16:57:49.624 23701 25649 W System.err: 	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
08-26 16:57:49.624 23701 25649 W System.err: 	at java.lang.Thread.run(Thread.java:761)
@KthProg

This comment has been minimized.

Copy link
Author

commented Aug 26, 2018

Here's what appear to be the logs when receiving the notification:

08-26 17:32:52.744 32427 32726 W FirebaseMessaging: Error while parsing timestamp in GCM event
08-26 17:32:52.744 32427 32726 W FirebaseMessaging: java.lang.NumberFormatException: null
08-26 17:32:52.744 32427 32726 W FirebaseMessaging: 	at java.lang.Integer.parseInt(Integer.java:483)
08-26 17:32:52.744 32427 32726 W FirebaseMessaging: 	at java.lang.Integer.valueOf(Integer.java:611)
08-26 17:32:52.744 32427 32726 W FirebaseMessaging: 	at com.google.firebase.messaging.f.a(Unknown Source)
08-26 17:32:52.744 32427 32726 W FirebaseMessaging: 	at com.google.firebase.messaging.f.a(Unknown Source)
08-26 17:32:52.744 32427 32726 W FirebaseMessaging: 	at com.google.firebase.messaging.FirebaseMessagingService.a(Unknown Source)
08-26 17:32:52.744 32427 32726 W FirebaseMessaging: 	at com.google.firebase.iid.c.run(Unknown Source)
08-26 17:32:52.744 32427 32726 W FirebaseMessaging: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
08-26 17:32:52.744 32427 32726 W FirebaseMessaging: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
08-26 17:32:52.744 32427 32726 W FirebaseMessaging: 	at java.lang.Thread.run(Thread.java:761)
08-26 17:32:52.748 32427 32726 W FirebaseMessaging: Error while parsing timestamp in GCM event
08-26 17:32:52.748 32427 32726 W FirebaseMessaging: java.lang.NumberFormatException: null
08-26 17:32:52.748 32427 32726 W FirebaseMessaging: 	at java.lang.Integer.parseInt(Integer.java:483)
08-26 17:32:52.748 32427 32726 W FirebaseMessaging: 	at java.lang.Integer.valueOf(Integer.java:611)
08-26 17:32:52.748 32427 32726 W FirebaseMessaging: 	at com.google.firebase.messaging.f.a(Unknown Source)
08-26 17:32:52.748 32427 32726 W FirebaseMessaging: 	at com.google.firebase.messaging.f.d(Unknown Source)
08-26 17:32:52.748 32427 32726 W FirebaseMessaging: 	at com.google.firebase.messaging.FirebaseMessagingService.a(Unknown Source)
08-26 17:32:52.748 32427 32726 W FirebaseMessaging: 	at com.google.firebase.iid.c.run(Unknown Source)
08-26 17:32:52.748 32427 32726 W FirebaseMessaging: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
08-26 17:32:52.748 32427 32726 W FirebaseMessaging: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
08-26 17:32:52.748 32427 32726 W FirebaseMessaging: 	at java.lang.Thread.run(Thread.java:761)
08-26 17:32:52.749 32427 32444 D FA      : Logging event (FE): notification_receive(_nr), Bundle[{firebase_event_origin(_o)=fcm, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=6840097104577902541}]
08-26 17:32:52.752 32427 32726 V RNPushNotification: onMessageReceived: Bundle[{userId=1, id=2, body=You have received a new trophy, data=8, type=TrophyReceived, title=Trophy Received, webSocketOnly=false}]
08-26 17:32:52.753 32427 32427 D ReactNative: ReactInstanceManager.ctor()
08-26 17:32:52.753 32427 32427 D ReactNative: ReactInstanceManager.createReactContextInBackground()
08-26 17:32:52.753 32427 32427 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
08-26 17:32:52.753 32427 32427 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundFromBundleLoader()
08-26 17:32:52.753 32427 32427 D ReactNative: ReactInstanceManager.recreateReactContextInBackground()
08-26 17:32:52.753 32427 32427 D ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
08-26 17:32:52.755 32427 32727 D ReactNative: ReactInstanceManager.createReactContext()
08-26 17:32:52.760 32427 32727 D ReactNative: Initializing React Xplat Bridge.
08-26 17:32:52.763 32427 32727 D ReactNative: Initializing React Xplat Bridge before initializeBridge
08-26 17:32:52.763 32427 32444 V FA      : Using measurement service
08-26 17:32:52.764 32427 32444 V FA      : Connecting to remote service
08-26 17:32:52.770 32427 32444 D FA      : Logging event (FE): notification_foreground(_nf), Bundle[{firebase_event_origin(_o)=fcm, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=6840097104577902541}]
08-26 17:32:52.773 32427 32727 D ReactNative: Initializing React Xplat Bridge after initializeBridge
08-26 17:32:52.773 32427 32727 D ReactNative: CatalystInstanceImpl.runJSBundle()
08-26 17:32:52.781 32427 32444 V FA      : Using measurement service
08-26 17:32:52.781 32427 32444 V FA      : Connection attempt already in progress
08-26 17:32:52.781 32427 32444 D FA      : Connected to remote service
08-26 17:32:52.781 32427 32444 V FA      : Processing queued up service tasks: 2
@KthProg

This comment has been minimized.

Copy link
Author

commented Aug 27, 2018

I fixed this. The problem was my fix for another issue. For anyone who detached this from Expo, and had this issue (#432), and copied the solution: in order to get the current instance of the react instance manager, you need to write it like this instead:

package host.exp.exponent;


import android.app.Activity;
import android.util.Log;

import com.facebook.react.ReactPackage;

import java.util.Arrays;
import java.util.List;

import expolib_v1.okhttp3.OkHttpClient;
import host.exp.expoview.Exponent;

// Needed for `react-native link`
// import com.facebook.react.ReactApplication;
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
import com.reactnativepayments.ReactNativePaymentsPackage;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactInstanceManager;

public class MainApplication extends ExpoApplication implements ReactApplication {

  @Override
  public boolean isDebug() {
    return BuildConfig.DEBUG;
  }

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  // Needed for `react-native link`
  public List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        // Add your own packages here!
        // TODO: add native modules!

        // Needed for `react-native link`
        // new MainReactPackage(),
        new ReactNativePushNotificationPackage(),
        new ReactNativePaymentsPackage()
    );
  }

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

    @Override
    public ReactInstanceManager getReactInstanceManager(){
      Log.d("ReactNativeHost", "Fetching manager from Exponent (override)");
      Activity activity = Exponent.getInstance().getCurrentActivity();
      if(activity instanceof MainActivity){
        return ((MainActivity)activity).getReactInstanceManager();
      }
      Log.d("ReactNativeHost", "Activity was not main activity");
      return null;
    }

    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new ReactNativePushNotificationPackage(),
        new ReactNativePaymentsPackage()
      );
    }
  };

  @Override
  public String gcmSenderId() {
    return getString(R.string.gcm_defaultSenderId);
  }

  @Override
  public boolean shouldUseInternetKernel() {
    return BuildVariantConstants.USE_INTERNET_KERNEL;
  }

  public static OkHttpClient.Builder okHttpClientBuilder(OkHttpClient.Builder builder) {
    // Customize/override OkHttp client here
    return builder;
  }
}

and update your main activity like so:

package host.exp.exponent;

import android.content.Intent;
import android.os.Bundle;

import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactPackage;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import abi23_0_0.com.facebook.react.ReactActivity;
import host.exp.exponent.generated.DetachBuildConstants;
import host.exp.exponent.experience.DetachActivity;

public class MainActivity extends DetachActivity {

  @Override
  public String publishedUrl() {
    return "exp://exp.host/@kthprog/2e-card-life";
  }

  @Override
  public String developmentUrl() {
    return DetachBuildConstants.DEVELOPMENT_URL;
  }

  @Override
  public List<String> sdkVersions() {
    return new ArrayList<>(Arrays.asList("27.0.0"));
  }

  @Override
  public List<ReactPackage> reactPackages() {
    return ((MainApplication) getApplication()).getPackages();
  }

  @Override
  public boolean isDebug() {
    return BuildConfig.DEBUG;
  }

  @Override
  public Bundle initialProps(Bundle expBundle) {
    // Add extra initialProps here
    return expBundle;
  }

    public ReactInstanceManager getReactInstanceManager(){
      return ((ReactInstanceManager)(Object)mReactInstanceManager.get());
    }

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    getReactInstanceManager().onActivityResult(this, requestCode, resultCode, data );
  }
}

@KthProg KthProg closed this Aug 27, 2018

@KthProg

This comment has been minimized.

Copy link
Author

commented Aug 27, 2018

As far as this repo goes, it needs to be updated to work with applications detached from Expo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.