Passing String between classes

Asked

Viewed 71 times

0

I got my main class where I got

... String ola = "Hello fellas";

and I have my other class:

public class NotificacaoDiaria extends BroadcastReceiver {
    @Override
    public void onReceive(Context arg0, Intent arg1) {
        Toast.makeText(arg0, "Funciona!!!", Toast.LENGTH_LONG).show();
        Toast t = Toast.makeText(this, ola, Toast.LENGTH_SHORT).show();
    }
}

I want this string to be interpreted here, not for this function, but so I can control it in this class.

1 answer

1


I’m not sure that’s what you’re looking for:

In the class you call the Broadcastreceiver

Intent intent .....
intent.putExtra("label", String);
sendBroadcast(intent);

At the Broadcastreceiver

public void onReceive(Context arg0, Intent arg1) {
   String teste = arg1.getStringExtra("teste"); 
   Toast.makeText(arg0, teste, Toast.LENGTH_LONG).show();
}

amendment provided by the author

  • in the main class of the certificate, only in the Broadcastreceiver you have to adapt: public void onReceive(Context arg0, Intent arg1) { String test = arg1.getStringExtra("test"); Maketoast.Text(arg0, test, Toast.LENGTH_LONG). show();}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.