简体   繁体   English

如何将字符串变量 java 从一种方法传递到另一种方法

[英]How pass string variable java from one method to another method

I am new on Java android code, please help me how to access String variable from one method to another method, this is from my code, I want to use variable deviceToken, to pass the value to another method that using javascriptinterface我是 Java android 代码的新手,请帮助我如何从一种方法访问字符串变量到另一种方法,这是来自我的代码,我想使用变量 deviceToken,将值传递给使用 javascriptinterface 的另一种方法

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onNewToken(String token) {
        Log.d("TokenFcm",token);

        String deviceToken = token ;

    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
    }
  1. by declaring deviceToken as instance variable, it can be accessed from anotherMethod of same class通过将 deviceToken 声明为实例变量,可以从相同 class 的另一个方法访问它
public class MyFirebaseMessagingService extends FirebaseMessagingService {

String deviceToken = "";

    @Override
    public void onNewToken(String token) {
        Log.d("TokenFcm",token);

         deviceToken = token ;

    }
    
    public void anotherMethod(){
     System.out.println(deviceToken);
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
    } ```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Java中将字符串从一个方法传递到另一个方法 - How to pass a string from one method to another method in Java 我如何通过 ArrayList<string> 在 Java 中从一种方法到另一种方法。 变量未初始化错误</string> - How do I pass an ArrayList<String> from one method to another in Java. Variable not initialised error android将变量从一种方法传递到另一种方法 - android pass variable from one method to another 如何在Java中将变量值从一种方法传递到另一种方法作为数据库查询的参数 - how to pass variable value from one method onto another as a parameter of database query in java 如何将变量从一个参数化方法传递到另一个? - How to pass variable from one parameterized method to another? Java,将字符串从一种方法传递到另一种方法 - Java, Passing a String from one method to another 如何将变量从一种方法传递到另一种方法? - How to pass variables from one method to another? 如何将String值从一个void方法传递到另一个void方法 - How to pass String value from one void method to another void method 如何在Java中使用另一种方法中的一个方法的变量(android) - How to use the variable of one method in another method in Java(android) 如何将值从一种方法传递到另一种方法 - How to pass the value from one method to another method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM