Intent from Fragment to Activity Intent from Fragment to Activity xml xml

Intent from Fragment to Activity


use this

public void goToAttract(View v){    Intent intent = new Intent(getActivity(), MainActivityList.class);    startActivity(intent);}

be sure you've registered MainActivityList in you Manifest


Try this code once-

public class FindPeopleFragment extends Fragment {@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,      Bundle savedInstanceState) {    View rootView = inflater.inflate(R.layout.fragment_home,        container, false);        Button button = (Button) rootView.findViewById(R.id.button1);        button.setOnClickListener(new View.OnClickListener() {        @Override        public void onClick(View v) {        updateDetail();        }        });        return rootView;        }public void updateDetail() {        Intent intent = new Intent(getActivity(), MainActivityList.class);        startActivity(intent);        }}

And as suggested by Raghunandan remove below code from your fragment_home.xml-

android:onClick="goToAttract"


Remove this

android:onClick="goToAttract"

Then

View rootView = inflater.inflate(R.layout.fragment_home, container, false);Button b = (Button)rootView.findViewById(R.id.button1);b.setOnClickListener(new OnClickListener(){     public void onClick(View v)     {        Intent intent = new Intent(getActivity(), MainActivityList.class);        startActivity(intent);     } });return rootView;

The error says you need to public void goToAttract(View v) in Activity class

Could not find method goToAttract(View) in the activity class

Reason pls check the answer by PareshMayani @

Android app crashing (fragment and xml onclick)

Edit:

Caused by: java.lang.OutOfMemoryError

I guess you have a image that is too big to fit in and it needs to be scaled down. Hence the OutOfMemoryError.