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

Pass React Native Promise between activities on Android [Kotlin] #17996

Closed
Pranit-Harekar opened this issue Feb 15, 2018 · 1 comment
Closed
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@Pranit-Harekar
Copy link

FYI: I am new to Android world.

What I am trying to do ?

I am using Native Modules for React Native Android. I am using react native promises instead of callbacks to do some async task. Simple and Easy.

In Detail

I have a native module called "ReactNativeBridge" which has bunch of methods which are marked with @ReactMethod so they can be accessed from React Native side.

class ReactNativeBridge(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
@ReactMethod
printImage(imageUrl: String, promise: Promise) {
    val currentActivity = currentActivity

     if (currentActivity == null) {
        promise.reject("Activity doesn't exist")
    }

    // Start activity which takes promise as an argument
     val intent = Intent(reactApplicationContext.applicationContext, PrintActivity::class.java).apply {
        putExtra(EXTRA_PRINT_DATA, somePrintData)
        putExtra(EXTRA_PRINT_PROMISE, promise)   // <---- here is the problem
    }

    currentActivity.startActivity(intent)
} }

As you can see I want to start a new Android activity in each of these methods and pass the Promise as an argument to those activities, through Intents. But I am unable to pass the promise through Intents since not all data types can be passed through Intents. I checked the type of promise, it is an Interface.

This is how a Promise Interface looks,

enter image description here

I know we cannot pass Interface since it is an abstract thing (like a blueprint).

** If your answer is "extend interface to Serializable" then remember I cannot modify Promise Interface. (It's a Facebook thing)

Questions

  1. How to pass a Promise type through Intent ?
  2. Is there any other approach to pass the Promise? Other than Intents.
@react-native-bot
Copy link
Collaborator

Thanks for posting this! It looks like your issue is missing some required information. Can you please add all the details specified in the Issue Template? This is necessary for people to be able to understand and reproduce your issue.

I am going to close this, but please feel free to open a new issue with the additional information provided. Thanks!

How to ContributeWhat to Expect from Maintainers

@react-native-bot react-native-bot added no-template Ran Commands One of our bots successfully processed a command. labels Feb 15, 2018
@facebook facebook locked as resolved and limited conversation to collaborators Feb 15, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Feb 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

2 participants