question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash app when build real device in Android

See original GitHub issue
  • Version: 2.0.0

I run into emulator, then even though it throws the error Attempt to invoke virtual method 'java.lang.String android.content.Intent.getAction()' on a null object reference. but sharing is still working. However when building a real device, after pressing share it will redirect to the host app but it maybe crash(restart app).

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

4reactions
vlesucommented, Nov 17, 2021

This also cause problems in another modules (for example, exception in RNPushNotifications…)

In my case, solution in file ReceiveSharingIntentModule.java was:

  private final ReactApplicationContext reactContext;
  private ReceiveSharingIntentHelper receiveSharingIntentHelper;
  private Intent oldIntent;  // <-- add this line

  protected void onNewIntent(Intent intent) {
    Activity mActivity = getCurrentActivity();
    if(mActivity == null) { return; }
    oldIntent = mActivity.getIntent();  // <-- add this line
    mActivity.setIntent(intent);
  }

  @RequiresApi(api = Build.VERSION_CODES.KITKAT)
  @ReactMethod
  public void getFileNames(Promise promise){
    Activity mActivity = getCurrentActivity();
    if(mActivity == null) { return; }
    Intent intent = mActivity.getIntent();
    receiveSharingIntentHelper.sendFileNames(reactContext, intent, promise);
    if (oldIntent != null) {  // <-- add this line
      mActivity.setIntent(oldIntent);  // <-- change this line from mActivity.setIntent(null); 
    }  // <-- add this line
  }
1reaction
jensdevcommented, Aug 17, 2022

Until this merges. You can use the snippet below. Put this in patches/react-native-receive-sharing-intent+2.0.0.patch and use https://www.npmjs.com/package/patch-package

diff --git a/node_modules/react-native-receive-sharing-intent/android/src/main/java/com/reactnativereceivesharingintent/ReceiveSharingIntentModule.java b/node_modules/react-native-receive-sharing-intent/android/src/main/java/com/reactnativereceivesharingintent/ReceiveSharingIntentModule.java
index f752144..d2542f9 100644
--- a/node_modules/react-native-receive-sharing-intent/android/src/main/java/com/reactnativereceivesharingintent/ReceiveSharingIntentModule.java
+++ b/node_modules/react-native-receive-sharing-intent/android/src/main/java/com/reactnativereceivesharingintent/ReceiveSharingIntentModule.java
@@ -18,6 +18,7 @@ public class ReceiveSharingIntentModule extends ReactContextBaseJavaModule {
 
   private final ReactApplicationContext reactContext;
   private ReceiveSharingIntentHelper receiveSharingIntentHelper;
+  private Intent oldIntent;
 
   public ReceiveSharingIntentModule(ReactApplicationContext reactContext) {
     super(reactContext);
@@ -30,6 +31,7 @@ public class ReceiveSharingIntentModule extends ReactContextBaseJavaModule {
   protected void onNewIntent(Intent intent) {
     Activity mActivity = getCurrentActivity();
     if(mActivity == null) { return; }
+    oldIntent = mActivity.getIntent();
     mActivity.setIntent(intent);
   }
 
@@ -40,7 +42,9 @@ public class ReceiveSharingIntentModule extends ReactContextBaseJavaModule {
     if(mActivity == null) { return; }
     Intent intent = mActivity.getIntent();
     receiveSharingIntentHelper.sendFileNames(reactContext, intent, promise);
-    mActivity.setIntent(null);
+    if (oldIntent != null) {
+      mActivity.setIntent(oldIntent);
+    }  
   }
 
   @ReactMethod
diff --git a/node_modules/react-native-receive-sharing-intent/src/ReceiveSharingIntent.ts b/node_modules/react-native-receive-sharing-intent/src/ReceiveSharingIntent.ts
index 735c191..91dab4b 100644
--- a/node_modules/react-native-receive-sharing-intent/src/ReceiveSharingIntent.ts
+++ b/node_modules/react-native-receive-sharing-intent/src/ReceiveSharingIntent.ts
@@ -33,7 +33,7 @@ class ReceiveSharingIntentModule implements IReceiveSharingIntent {
     }
 
     clearReceivedFiles(){
-        this.isClear = true;
+        ReceiveSharingIntent.clearFileNames();
     }
 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Studio app crashes on real device, but works on ...
Android Studio app crashes on real device, but works on emulator · Can you post the output from the Logcat regarding the crash?...
Read more >
Crashes - Android Developers
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. ... An app crash on an Android...
Read more >
Why Do My Apps Keep Crashing on Android? - Avast
1. The “Force stop” method · 2. Restart your Android device · 3. Keep your phone updated · 4. Clear your cached data...
Read more >
How to Resolve App Crashes in Android Studio?
Solutions to fix App Crash · 1. Observe the App Crash · 2. Find the Stack Trace · 3. Investigation Techniques · 4....
Read more >
My Android all runs on emulator but crashes on the device ...
Adjust the minSdkversion in gradle(app level) . Or else the best solution would be to allow usb debugging in your phone's developer option...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found