Send Activity parameters to a calculation class

Asked

Viewed 175 times

0

I’ve had a question for a while, I posted it here once, but it hasn’t been solved. I would like to pass a parameter from an Activty to a calculus class (this class does not have Activity , it is only to calculate). I researched a lot about it and did not find, because what I see is passage between Ctivitys.

I have some doubt in this because in the recovery of the parameters, we put the intents inside public onCreat and when creating a new class does not have this. How would I do that?

Sorry I didn’t post code to help or anything, I’m by phone.

Thank you all for your attention.!

I would like to do something like that. Is it possible? If it is, what is the right way to do it? [insert image description here] (https://i.stack.Imgur.com/Ai64u.png)inserir a descrição da imagem aqui

  • It would not be useful to instantiate the class for example: Classe_calculo example = new Classe_calculo(); example.calculate();` this does not work?

  • put the Activity and calculus class code ; )

  • Hi guys. I’m by cell phone, so I have no way to post. Basically how to receive information from an Activity in a class. How I will recover there with the Intent if you do not have onCreat to the Voce create a new class.

  • Look, I only see 2 ways to do this: Either you register this Activity object somewhere so that your data is accessible in a Singleton class, for example, or you create a generic controller and arrow the Activity data in it. If the target parameters you want change frequently, it is best to keep the Activity object reference even.

  • I put a picture of what I’d like to do!!

1 answer

0

Creating the class:

public class MinhaClasse {
    Context context;
    ProgressDialog progressDialog;
    String nomedoarquivo;
    String servidorremoto;
    Handler handler;


    public MnhaClasse(Context context, 
                      String arquivo, 
                      String servidorremoto, 
                     Handler handler ) {
        this.context = context;
        this.nomedoarquivo = arquivo;
        this.servidorremoto = servidorremoto;
        this.handler = handler;
    }
    ....

In Activity you instantiate the class by passing the parameters and call the execute method of the same.

new MinhaClasse(getActivity(), arquivo, servidorremoto,myHandler).execute(arquivo);

Browser other questions tagged

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