Logs printed to the console are increasing on each new transaction - RN(JS)+Native(Java)

Viewed 45

I made an app that sending strings with a text selection pop-up menu from outside the app to the app (Pic-1). This string is printed to console in the application. But as you can see, the number of these strings printed to the console increases each time a new string is sent (Pic-2). I wrote the whole application with the codes below. How can I solve that problem?

enter image description here

Console.log problem

enter image description here

App.js

import React, { useEffect } from "react"
import {DeviceEventEmitter, View, Text} from "react-native"


export default function App() {

    useEffect(() => {
        DeviceEventEmitter.addListener("EventReminder", (data) => {
            console.log(data.eventProperty)
        })
    }, [])
    return (
      <View></View>
    )
}

AndoridManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.translationapp">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.PROCESS_TEXT" />
            <data android:mimeType="text/plain"/>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>        
      </activity>
    </application>
</manifest>

MainActivity.java

package com.translationapp;

import com.facebook.react.ReactActivity;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import java.util.Objects;

public class MainActivity extends ReactActivity {

  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
  @Override
  protected String getMainComponentName() {
    return "translationApp";
  }

  @Override
  public void onConfigurationChanged(@NonNull Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    getReactInstanceManager().onConfigurationChanged(this, newConfig);
  }

  @RequiresApi(api = Build.VERSION_CODES.M)
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(null);

    if (getIntent().getAction() != null && getIntent().getStringExtra(Intent.EXTRA_PROCESS_TEXT) != null) {
      String text = Objects.requireNonNull(getIntent().getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT)).toString();

      WritableMap params = Arguments.createMap();
      params.putString("eventProperty", text);


      sendEvent(Objects.requireNonNull(getReactInstanceManager().getCurrentReactContext()), params);
    }
  }

  private void sendEvent(ReactContext reactContext, @Nullable WritableMap params) {
    reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit("EventReminder", params);
  }
}

0 Answers
Related