-4

I have a Java Class in my Android project, where I wanted to separate facebook authorization from email authorization. Because of this line

 LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email", "public_profile"));

I was obliged to extend my FBLogin class from Activity. Did I do it right or I should have done in other way?

But my main Question is - how to show a Toast message in this FBLogin class? this line shows me errors

Toast.makeText(getActivity(), "Success", Toast.LENGTH_SHORT).show();
  • 1
    if `FBLogin ` class extends Activity then use `FBLogin.this` instead of `getActivity()` – ρяσѕρєя K Jan 19 '16 at 08:59
  • just replace getActivity() with yourclas.this – justDroid Jan 19 '16 at 09:00
  • Can you post some more code of the place you are calling Toast.makeText(...) ? Toast works in UI thread are you sure you are not calling it from another thread? The stacktrace of the errors also could be handy if you post it. – pleft Jan 19 '16 at 09:05

3 Answers3

1

Try to use:

Toast.makeText(fblogin.this, "Success", Toast.LENGTH_SHORT).show();
Unii
  • 1,587
  • 15
  • 33
0

For normal Activity:

Toast.makeText(FBLogin.this, "Success", Toast.LENGTH_SHORT).show();

extends Fragment:

Toast.makeText(getActivity(), "Success", Toast.LENGTH_SHORT).show();
Uma Kanth
  • 5,659
  • 2
  • 20
  • 41
MurugananthamS
  • 2,395
  • 4
  • 20
  • 49
0

Do this

Toast.makeText(YourClassName.this, "Success", Toast.LENGTH_SHORT).show(); 

Like if your Class Name is MainActivity then you have to do this

Toast.makeText(MainActivity .this, "Success", Toast.LENGTH_SHORT).show();

or you can pass Context of your Application.

Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
Chintan Bawa
  • 1,376
  • 11
  • 15