Execute a function from a class [closed]

-1

I would like to know if it is possible to execute a certain function only when the activity is called by another particular activity . for example: Activity A called Activity B , in this case execute Y function, but if Activity C call Activity B DO NOT execute Y function.

    
asked by anonymous 06.01.2017 / 12:35

1 answer

3

What you can do is pass values to Activity B. Verify that when it is called, there is some value in Intent of it and treat your algorithm. More or less like this:

Activity A calling 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)

In Activity B: Checks whether the value of Activity was passed to another Activity

Intent intent = getIntent(); // pegando o Intent
String id = intent.getStringExtra("id"); // pegando Valor do Intent
if (id == "seuValor")
    executarFuncao(id);
    
06.01.2017 / 12:46