error: cannot find symbol finish(); in my own module

error: cannot find symbol finish(); in my own module

我想从我自己的模块访问 finish() 方法。但显示此错误:错误:找不到符号 完成();

如何从我自己的模块访问 finish() 方法?

这是我的代码:


//ExitModule.java
package com.security_notifier;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;


public class ExitModule extends ReactContextBaseJavaModule {

    public ExitModule(ReactApplicationContext reactContext) {
        super(reactContext); //required by React Native
    }

    @Override
    //getName is required to define the name of the module represented in JavaScript
    public String getName() {
        return "Exit";
    }

    @ReactMethod
    public void finishApp() {
        finish();
    }
}

我是 React Native 的新手。我非常需要你的帮助。

我已经解决了问题:

//ExitModule.java
package com.security_notifier;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactContext;
import android.app.Activity;

public class ExitModule extends ReactContextBaseJavaModule {

    private ReactContext mReactContext;
    public ExitModule(ReactApplicationContext reactContext) {
        super(reactContext); //required by React Native
        mReactContext = reactContext;
    }


    @Override
    //getName is required to define the name of the module represented in JavaScript
    public String getName() {
        return "Exit";
    }

    @ReactMethod
    public void finishApp() {
        Activity activity = mReactContext.getCurrentActivity();
        activity.finish();
    }
}

这是我的SplashActivity.java

package com.YOUR_NAME;

import android.content.Intent;
import android.os.Bundle;
//import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;

public class SplashActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}