send data to another activity android code example
Example 1: send variable intent
String sessionId = getIntent().getStringExtra("EXTRA_SESSION_ID");
Example 2: go to activity android
btListe = (ImageButton)findViewById(R.id.Button_Liste);
btListe.setOnClickListener(new OnClickListener()
{ public void onClick(View v)
{
intent = new Intent(main.this, ListViewImage.class);
startActivity(intent);
finish();
}
});
Example 3: send variable intent
Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("EXTRA_SESSION_ID", sessionId);
startActivity(intent);
Example 4: pass data from activity to fragment android
Bundle bundle = new Bundle();
bundle.putString("edttext", "From Activity");
Fragmentclass fragobj = new Fragmentclass();
fragobj.setArguments(bundle);
And inside fragment:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String strtext = getArguments().getString("edttext");
return inflater.inflate(R.layout.fragment, container, false);
}
Example 5: android pass object to activity
Customer customerObjInToClass = getIntent().getExtras().getParcelable("myCustomerObj");
Example 6: how to pass data from activity to fragment
passing data from activity to fragment