Create separate method to call Activity

Asked

Viewed 1,059 times

0

i created a script where I intend to call separate activities

but it’s not working

package com.example.john.new_login;

import android.content.Context; import android.content.Intent;

import com.example.john.new_login.login.Registration; import com.example.john.new_login.login.Password recovery;

/** * Created by John on 09/12/2017. */

public class Botoes_login {

private static Context context;

public static void Registro() {
    Intent registro = new Intent(context, Cadastro.class);
    context.startActivity(registro);
}

public static void RecuperaSenha() {
    Intent recuperasenha = new Intent(context, RecuperaSenha.class);
    context.startActivity(recuperasenha);
}

public static void Login() {
    Intent login = new Intent(context, Login.class);
    context.startActivity(login);
}

}

how it would be the right way to create a class for this?

1 answer

0


Let me get this straight.

You have created a Chamaractivities class with some methods. Then you intend to give, for example, Chamaractivities.Login() for the method already make the transition of Activities? If yes, I believe your script already works, you should only, before calling the method, fill the context attribute with the current screen context. But I recommend you take this static attribute and pass the context by parameter.

Ex:

ChamarActivities.Login(MainActivity.this);

If what I said doesn’t work, I think I’m making some other mistake, what would it be?

  • 1

    was exactly that, I was forgetting to pass the Context to the classes, this way, n would work even, thank you

Browser other questions tagged

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