CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2021-05-11
by shirley

Original Post

Original - Posted on 2013-04-16
by Shiv



            
Present in both answers; Present only in the new answer; Present only in the old answer;

From an Activity you can send data to a Fragment with the intent as:
Bundle bundle = new Bundle(); bundle.putString("message", "From Activity");
// Set Fragmentclass Arguments Fragmentclass fragobj = new Fragmentclass(); fragobj.setArguments(bundle);
And to receive a fragment in the Fragment onCreateView method:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { String strtext = getArguments().getString("message");
return inflater.inflate(R.layout.fragment, container, false); }
This method also works with multiple Fragments. just use `setArguments()` method.
**Step 1**: To send data from a fragment to an activity
Intent intent = new Intent(getActivity().getBaseContext(), TargetActivity.class); intent.putExtra("message", message); getActivity().startActivity(intent);
**Step 2**: To receive this data in an Activity:
Intent intent = getIntent(); String message = intent.getStringExtra("message");
**Step 3**: To send data from an activity to another activity, follow the normal approach
Intent intent = new Intent(MainActivity.this, TargetActivity.class); intent.putExtra("message", message); startActivity(intent);
**Step 4**: To receive this data in an activity
Intent intent = getIntent(); String message = intent.getStringExtra("message");
**Step 5.**: From an Activity you can send data to a Fragment with the intent as:
Bundle bundle = new Bundle(); bundle.putString("message", "From Activity");
// Set Fragmentclass Arguments Fragmentclass fragobj = new Fragmentclass(); fragobj.setArguments(bundle);
And to receive a fragment in the Fragment onCreateView method:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { String strtext = getArguments().getString("message");
return inflater.inflate(R.layout.fragment, container, false); }


        
Present in both answers; Present only in the new answer; Present only in the old answer;