Run a function from a class

Asked

Viewed 58 times

-1

I wonder if there is possibility to perform a certain function only when the Activity is called by another determined Activity specific. for example: Activity A called the Activity B, in this case perform the function Y, but if the Activity C call on Activity B DO NOT perform the function Y.

  • I don’t know how you want to implement this, but an option would be to pass parameters to the Activity C of the caller and link the execution of the Y function to the condition of this parameter.

  • Thanks my noble, I managed to solve. I thank you for your help!

1 answer

3

What you can do is pass values to the Activity B. Check if when called, there is some value in Intent and treat your algorithm. Sort of like this:

Activity A calling a B:

Intent i=new Intent(context, ActivityB); // como passar valor de activity para outra
i.putExtra("id", "seuValor"); // setando valor
context.startActivity(i); // startando a nova activity (B)

Na Activity B: Check whether the value of Activity to another Activity

Intent intent = getIntent(); // pegando o Intent
String id = intent.getStringExtra("id"); // pegando Valor do Intent
if (id == "seuValor")
    executarFuncao(id);
  • Thanks for your help Diego!!!! I managed to solve my question. A hug.

  • ball show!!!

Browser other questions tagged

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