I was trying to go to another page using button
, but it always fail.
Here is my First Class with its XML:
public class Fin
use getContext() instead of MainActivity.this
Intent intent = new Intent(getContext(), SecondActivity.class);
startActivity(start);
For Kotlin you can use
val myIntent = Intent(activity, your_destination_activity::class.java)
startActivity(myIntent)
You need to use getActivity() method from fragment for Intents.
Intent intent = new Intent(getActivity(), SecondActivity.class);
startActivity(intent);
in your receiving intent use as
Intent intent = getActivity().getIntent();
((TextView)view.findViewById(R.id.hello)).setText(intent.getStringExtra("Hello"));
and in your send intent
Intent intent = new Intent(getActivity(),Main2Activity.class);
intent.putExtra("Hello","Nisar");
getActivity().startActivity(intent);
remember both are in fragments
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
.