1.Fragment Jump to activity
Jumping from fragment is similar to jumping from activity, except that you first get to show the activity of this fragment through the Getactivity method of fragment, the specific code is this:
Button button = view.findViewById(xxx);
button.setOnClickListener(
new
View.OnClickListener(
onClick(View view)
{
startActivity(
new
Intent(getActivity(), SettingActivity.
class
));
}
));
If you want to return a result, you can have two similar methods:
Jump directly from the fragment
Startactivityforresult (Intent, Request_code);
This notation receives the returned result to rewrite the Onactivityresult () method in fragment;
Jump from activity
Getactivity (). Startactivityforresult (Intent, Request_code);
This is the way to rewrite the Onactivityresult () method in the activity.
2. Fragment Jump to Fragment
Fragment newfragment = Newexamplefragment ();
Fragmenttransaction transaction =getfragmentmanager (). BeginTransaction ();
Transaction.replace (r.id.fragment_container,newfragment);
Transaction.commit ();
Go Fragment jump to activity or fragment