View Toast in non-activity class

0

I'd like to display Toast when the user makes logout .

I have this structure:

WithinConexaoFirebase,IhaveamethodcalledlogOut:

publicstaticvoidlogOut(){firebaseAuth.signOut();}

andwithintheclassPerfilActivity,IhaveamethodthatcallslogOut():

privatevoideventoClicks(){btnLogOut.setOnClickListener(newView.OnClickListener(){@OverridepublicvoidonClick(Viewv){ConexaoFirebase.logOut();finish();}});}

IwouldlikeeverytimeImadelogouttodisplayaToast,soItriedthefollowing:

WithinConexãoFirebase,Icreatedamethodcalledalert:

privatevoidalert(Strings){Toast.makeText(getApplicationContext(),s,Toast.LENGTH_SHORT).show();}

andwithinlogOutIcalledalertpassingthemessagethatIwanttobedisplayed,butmycodegoterror:

What is the correct way to display the message?

I know I could do Toast within CadastrarActivity , but I would like to do within the ConexaoFirebase class.

    
asked by anonymous 23.12.2017 / 02:53

1 answer

1
public static void logout(Context ctx) {
    auth.signOut();
    alert(ctx, "...");
}

private void alert(Context ctx, String s) {
    Toast.makeText(ctx, s, Toast.LENGTH_SHORT).show();
}

The logout method receives the parameter Context and then passes to the alert method that will display its Toast . Basically, all Toast will require Context to be displayed.

ConexaoFirebase.logout(getApplicationContext());

    
23.12.2017 / 03:19