0

I created an object of the Intent class called receiverIntent, to receive a variable from the previous class:

Intent receiverIntent = getIntent();

Then I created a variable called completeName, to receive a variable called "name", through an Intent:

    String completeName = receiverIntent.getStringExtra("name");

But I want to send this completeName variable to another class without needing to use Intent. For that I tried using public static. But error happens.
It Displays the following error in the receiverIntent object: "Non-static field receiverIntent cannot be referenced from a static context": https://uploaddeimagens.com.br/imagens/UHWNTaY

Please, how can I make the completeName variable as being public and static so that another class can recognize this variable called completeName without an error?

  • If you want a simple solution, you could just make a [singleton](https://stackoverflow.com/questions/51344683/how-to-keep-arraylist-value-when-changing-activity-in-android/51344957#51344957) – Tyler V Sep 18 '21 at 01:38

1 Answers1

0

If you want to pass a complete name value to another activity/class you can do it with same approach as you did in this example. Put name in the intent extras and extract it when another activity/class is launched.

Matija Sokol
  • 107
  • 6