I have a little problem: I have 3 Activity. Activity ListClass.java
public class ListClass extends Activity { ...... listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { onItemClick1(parent, view, position, id); } }); } public void onItemClick1(AdapterView<?> parent, View view, int position, long id) { String name = (String) parent.getItemAtPosition(position); String address = (String) listAddress.get(position); int status = (int) listStatus.get(position); double lat = (double) listLat.get(position); double lng = (double) listLng.get(position); String serialNumber = (String) listSerialNumber.get(position); getIntent().putExtra("name", name); getIntent().putExtra("address", address); getIntent().putExtra("status", status); getIntent().putExtra("latitude", lat); getIntent().putExtra("longitude", lng); getIntent().putExtra("serialNumber", serialNumber); startActivity(getIntent()); } public Intent getIntent() { Intent intent = new Intent(ListClass.this, ClassB.class); return intent; } As you can see I putExtra values that I use on ClassB.java :
public class ClassB extends Activity { TextView textViewTitle; TextView textView2; TextView textViewInfo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.charge_box); this.textViewTitle = (TextView) findViewById(R.id.charge_box__textView1); this.textView2 = (TextView) findViewById(R.id.charge_box__textView2); this.textViewInfo = (TextView) findViewById(R.id.charge_box__textView3); getActionBar().setDisplayHomeAsUpEnabled(true); Bundle bundle = getIntent().getExtras(); String name = bundle.getString("name"); String address = bundle.getString("address"); int status = bundle.getInt("status"); textViewTitle.setText(name); textViewInfo.setText(address + " " + status); } } SO FAR SO GOOD! But I need to start ActivityB from another activity that is MainClass.java.
Intent intent = new Intent(MainActivity.this, ClassB.class); startActivity(intent); the problem is that when ClassB uses Bundle bundle = getIntent().getExtras(); he doesn't find "extras" because Intent of MainClass is different from Intent of ListClass! how can I do?? can I decide which Intent use? tahnk you!
EDIT: @skygeek ok I'm working on it, but how can I create a static variable if the extra values change?
public void onItemClick1(AdapterView<?> parent, View view, int position, long id) { String name = (String) parent.getItemAtPosition(position); String address = (String) listAddress.get(position); int status = (int) listStatus.get(position); double lat = (double) listLat.get(position); double lng = (double) listLng.get(position); String serialNumber = (String) listSerialNumber.get(position); Intent intent = new Intent(ListClass.this, ChargeBoxInfoActivity.class); intent.putExtra("name", name); intent.putExtra("address", address); intent.putExtra("status", status); intent.putExtra("latitude", lat); intent.putExtra("longitude", lng); intent.putExtra("serialNumber", serialNumber); startActivity(intent); }