Android – Transmitere informație

Varianta 1.

Transmitere de date între Fragment și Activity:

Intent intent =newIntent(getActivity().getBaseContext(),TargetActivity.class);
intent.putExtra("message", message);
getActivity().startActivity(intent);

 

Varianta 2.

Primire informație în Activity:

Intent intent = getIntent();
String message = intent.getStringExtra("message");

 

Varianta 3.

Transmitere de date între Activity și Activity:

Intent intent =newIntent(MainActivity.this,TargetActivity.class);
intent.putExtra("message", message);
startActivity(intent);

 

Varianta 4.

Primire informație în Activity

Intent intent = getIntent();
String message = intent.getStringExtra("message");

 

Varianta 5.

Transmitere de date între Activity și Fragment:

Bundle bundle=newBundle();
bundle.putString("message","From Activity");//set Fragmentclass ArgumentsFragmentclass fragobj=newFragmentclass();
fragobj.setArguments(bundle);

Varianta 6. 

Primire  informație în Fragment:

@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState)
{
   String strtext=getArguments().getString("message");
   return inflater.inflate(R.layout.fragment, container,false);
}
Advertisements
Android – Transmitere informație

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s