Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to switch from Fragment to Activity / Activity to Fragment in Android Programming
    text
    copied!<p>Currently, I am mainly using Fragments to connect to Facebook. </p> <p>However, for the other codes, I am using normal activites (no Fragments). </p> <p>My issue now is that I wish to have a button to link from my "Home Page" to the Fragment, and from the Fragment back to my "Home Page"</p> <p>I am unable to do so. </p> <p>I tried to use the same code to switch between activities for this but it does not work. </p> <p>Is there a way to Link Normal Activities to Fragments and Vice Versa ? Or can they only link to each other ? </p> <p>This is my Code:</p> <pre><code> public class SplashFragment extends Fragment{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.splash, container, false); // return view; Button btnNextScreen = (Button) view.findViewById(R.id.btnNextScreen); // Button btnNextScreen = (Button) findViewById(R.id.btnNextScreen); //Listening to button event btnNextScreen.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { //Starting a new Intent Intent nextScreen = new Intent(**getApplicationContext()**, SecondScreenActivity.class); startActivity(nextScreen); } }); return view; } } </code></pre> <p>I am getting an error at getApplicationContext().</p> <p>If I change it to getActivity(), they will prompt with another error that they are expecting to switch to a Fragment, not an activity. </p> <p>Thank you for your help !</p> <p>Regards, AndroidStudent</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload