How to reference Current Activity in ReactActivityLifecycleListener within a Expo Package?

26 Views Asked by At

I am currently developing an Expo module that utilizes Intents to receive content from other applications. My issue currently is that, while the app is open in the background, a share intent is unsuccessful.

The issues is also outlined in this questions.

To resolve this, I need to hook into the Android lifecycle as described here. And here I am bit confused on how to access the current activity to set the intent?

What I basically want to achieve is this:

protected void onNewIntent(Intent intent) {
  Activity mActivity = getCurrentActivity();
  if(mActivity == null) { return; }
  mActivity.setIntent(intent);
}

But how can I accomplish this within Expo Package, as opposed to a Module? How can I get the Current Activity in this snippet?

android/src/main/java/expo/modules/mylib/MyLibReactActivityLifecycleListener.kt
package expo.modules.mylib

import android.app.Activity
import android.os.Bundle
import expo.modules.core.interfaces.ReactActivityLifecycleListener

class MyLibReactActivityLifecycleListener : ReactActivityLifecycleListener {
  override fun onNewIntent(intent: Intent): Boolean {
    // Your setup code in `Activity.onCreate`.
    doSomeSetupInActivityOnCreate(activity)
  }
}

Thanks a lot in advance for any ideas.

0

There are 0 best solutions below