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(); } });
source share