Toast in Fragment, should use getActivity () or getAcitivity (). GetApplicationContext ()?

Sorry for my newbie. Question, I just can not find the answer from google and stackoverflow .. I am just starting to learn for Android, the desire can create a good base for knowledge of Android. I am wondering what should I use in the following if I create toast.maketext in a fragment. getActivity () or getAcitivity (). getApplicationContext ()?

I tried both, it works well.

btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getActivity(), "hello",Toast.LENGTH_LONG).show(); Toast.makeText(getActivity().getApplicationContext(),"Hello",Toast.LENGTH_LONG).show(); } }); 
+6
source share
1 answer

For calls related to the user interface, the Activity context is used.

See this explanation by Reto Meyer: fooobar.com/questions/12177 / ...

+10
source

All Articles